I am using Object Caching in C# to store an EntityCollection in Cache.
Following is the code for caching :
ObjectCache cache = MemoryCache.Default;
const string keyName = "BrandPartners";
EntityCollection result;
if (!cache.Contains(keyName))
{
result = GetCustomerData(service, firstName, lastName, gender);
var cacheItemPolicy = new CacheItemPolicy()
{
AbsoluteExpiration = DateTime.Now.AddMinutes(5)
};
tracingService.Trace("Writing into the cache");
cache.Add(keyName, result, cacheItemPolicy);
}
else
{
result = (EntityCollection)cache.Get(keyName);
tracingService.Trace("Data already found in the cache");
}
So, when I am first creating a record in an entity in an instance in CRM online, I am getting the trace : "Writing into the cache."
But, when I am again creating a record in the same entity, I am again getting the same trace ("Writing into the cache"). But, if I am using caching, I should not get this trace because the keyName of "BrandPartners" already exist in the cache.
So, what am I doing wrong?
Here are some possible reasons why you're not seeing a cached value being found:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.