Sunday, 17 March 2013

Portal Accelerator & Adxstudio - How to force clear Cache?

Caching is an important part of all enterprise applications, they help deliver high-performance and scalability. 

For those of you that do not understand caching, in short the caching manager will cache objects in memory the first time they are requested, and reuse these to feed further requests. 

Both Microsoft Portal Accelerator and AdxStudio Portal use caching. Cache invalidation seems to be an issue that many are currently experiencing. There are some built in features such as the Web Notification URL in CRM, but recently I was asked if there was a method of forcing the cache to clear programmatically.

How to clear the Cache Example
  1.         /// <summary>
  2.         /// Removes all items, clears everything from the Cache
  3.         /// </summary>
  4.         public void ClearCache()
  5.         {
  6.             var cache = Microsoft.Xrm.Client.Caching.ObjectCacheManager.GetInstance(null);
  7.             Microsoft.Xrm.Client.Caching.ObjectCacheManager.Clear(cache);
  8.         }
  9.  
  10.         /// <summary>
  11.         /// Removes an item from the cache
  12.         /// </summary>
  13.         /// <param name="item"></param>
  14.         public void ClearCache(string item)
  15.         {
  16.             var cache = Microsoft.Xrm.Client.Caching.ObjectCacheManager.GetInstance(null);
  17.             cache.Remove(item);
  18.         }

No comments:

Post a Comment

Action Microsoft.Crm.Setup.Common.Analyzer +CollectAction failed. Fatal error during installation

When installing the Srs Data Connection (Microsoft Dynamics CRM Reporting Extensions), you may have experienced the following error: ...