I have following problem: When I deploy dll of my application, database is overloaded with qeuries. I assume that there is some queue for incoming requests and while new dll is being loded, requests are queued. When dll is ready, requests are processed.
I store many database results to cache in web application. The problem is, that some data, which should be read only once from DB and next time from cache, is stored to the cache 10 and more times (that means data was read 10 and more times from db). I tried
to solve like this:
object o = MyCache.GetDataWithWait("key");
if(o == null)
{
MyCache.SetData("key-wait", true);
// Read data from DB and store it to the cache with "key"
MyCache.SetData("key-wait", false);
}
-----------------------------------
public static object GetDataWithWait(string key)
{
Cache mycache = System.Web.HttpContext.Current.Cache;
object o = mycache[key];
if (o == null)
{
object wait = mycache["key-wait"];
if (wait != null && Convert.ToBoolean(wait))
{
Thread.Sleep(7000);
o = mycache[key];
}
}
return o;
}
but it doesn't seem to be working, object is still stored to cache more than once. Any ideas?
jirhi
0 Points
5 Posts
Database query count optimalization
Dec 03, 2011 12:19 PM|LINK
Hi,
I have following problem: When I deploy dll of my application, database is overloaded with qeuries. I assume that there is some queue for incoming requests and while new dll is being loded, requests are queued. When dll is ready, requests are processed. I store many database results to cache in web application. The problem is, that some data, which should be read only once from DB and next time from cache, is stored to the cache 10 and more times (that means data was read 10 and more times from db). I tried to solve like this:
object o = MyCache.GetDataWithWait("key");
if(o == null)
{
MyCache.SetData("key-wait", true);
// Read data from DB and store it to the cache with "key"
MyCache.SetData("key-wait", false);
}
-----------------------------------
public static object GetDataWithWait(string key)
{
Cache mycache = System.Web.HttpContext.Current.Cache;
object o = mycache[key];
if (o == null)
{
object wait = mycache["key-wait"];
if (wait != null && Convert.ToBoolean(wait))
{
Thread.Sleep(7000);
o = mycache[key];
}
}
return o;
}
but it doesn't seem to be working, object is still stored to cache more than once. Any ideas?