countrymeister
asked on
WCF and caching
I have implemented caching in a WCF service hosted in a windows service
When my windows service starts I cache a dataset.
Now when my client calls the WCF service hosted in the windows service.
I noticed that the very first call takes a long time because it cannot find the cache.
ObjectCache cache = MemoryCache.Default;
if (cache.Contains(pCacheKey) )
listPortfolios = (List<P>)cache.Get(pCacheK ey);
else
{
get data and add to cache
}
When my windows service starts I cache a dataset.
Now when my client calls the WCF service hosted in the windows service.
I noticed that the very first call takes a long time because it cannot find the cache.
ObjectCache cache = MemoryCache.Default;
if (cache.Contains(pCacheKey)
listPortfolios = (List<P>)cache.Get(pCacheK
else
{
get data and add to cache
}
What is your question?
ASKER
The question is I am pretty sure the cache has the data, because my windows service loads the cache every morning.
But the very first call from the client takes a long time, the subsequent calls get the data back quickly .
My question is why does the very first call take a long time.
But the very first call from the client takes a long time, the subsequent calls get the data back quickly .
My question is why does the very first call take a long time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
here is my code, I am using System.Runtime.Caching, I have done the checks you mentioned.
The wcf service is hosted in a windows service
Checking further on this
ObjectCache cache = MemoryCache.Default;
if (!cache.Contains(pCacheKey ))
CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
cacheItemPolicy.AbsoluteEx piration = DateTime.Now.AddHours(24.0 );
cache.Add(pCacheKey, data, cacheItemPolicy);
The wcf service is hosted in a windows service
Checking further on this
ObjectCache cache = MemoryCache.Default;
if (!cache.Contains(pCacheKey
CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
cacheItemPolicy.AbsoluteEx
cache.Add(pCacheKey, data, cacheItemPolicy);
ASKER
On another note, I also tested adding debug in my windows hosted wcf service, verifying the dat is in the cache.
Yet the first call from my WPF client tries to get data from the db instead of the cache.
Yet the first call from my WPF client tries to get data from the db instead of the cache.
At which point(s) in your application is the database accessed for the purpose of loading the cache?
ASKER
When the window service starts , I have a background thread that loads all the required data in cache.
So in my testing in debug mode, I verified that the wcf service hosted in windows service has the cached data with the respective cache keys.
Once I verified that, I started my client and then made a service call to get the data and when I step through in debug mode again in my client, I notice that it tries to relaod the cached data.
Now is this the issue in debug mode per se, or should I be installing my service using install util and checking if this behaviour exists.
So in my testing in debug mode, I verified that the wcf service hosted in windows service has the cached data with the respective cache keys.
Once I verified that, I started my client and then made a service call to get the data and when I step through in debug mode again in my client, I notice that it tries to relaod the cached data.
Now is this the issue in debug mode per se, or should I be installing my service using install util and checking if this behaviour exists.
ASKER
Not much help provided I am closing this question