File Dependency Caching

Topics: Caching Application Block
Aug 5, 2009 at 5:26 PM

Hello,
         I am using Enterprise Library 4.1 Caching mechanism. I have an xml and which will be updated once in 2 months. So I thought of trying to have caching based on file dependency. Everything works fine for me. Once the xml file modified it updates the cache immediately. But one thing i noticed if there is not hit for sometimes around 30-40 mins (not sure whether it is always 30-50 mins). Probably after a gap of around 45 mins it updates the cache again. If i am right it should update only when there is an xml change. I didn't drop any dll or restart IIS or not even change web.config. What coudl be the reason? below i am providing by sample code which i am using
 
 
MenuCacheMgr = ICacheManager MenuCacheMgr;CacheFactory.GetCacheManager() as CacheManager;
Dictionary<string, string> MenuList = null;
if (MenuCacheMgr["MenuContentsList"] == null)
{
MenuCacheMgr.Flush();
}
 if ( !MenuCacheMgr.Contains("MenuContentsList"))
{
 
if (System.IO.File.Exists(MenuLocation))
{

 FileDependency expirationNotice = new FileDependency(MenuLocation);
 //... do some operations to update dictionary object

 MenuCacheMgr.Add("MenuContentsList", MenuList, CacheItemPriority.NotRemovable, null, expirationNotice);
}
else
{
 // read from cache

 MenuList = (Dictionary<string, string>)MenuCacheMgr["MenuContentsList"];
}
 
 
Do Let me know what could be problem?
 
Regards,
Elango

 

Aug 6, 2009 at 11:03 AM

What do you mean by no hit? You mean the cache doesnt get updated after the file does get updated, after a successful update of the cache? is that it?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 6, 2009 at 4:23 PM

Sorry for not making my question clear. Currently the Cache gets updated if the file is updated.  If i am right it should update the cache only if the file is updated or restart of IIS or dropping some dependent dlls. But for me cache is getting updated in following case.

When there is no request for 30-45 mins and very next request is again updating cache instead of reading the existing cache. We didn't do any change to xml file or not even dropped new dll or didn't restart any IIS. Don't know why cache is getting cleared after specific interval of time. If request keep on flowing then looks like it retains the cache till the file gets updated or it reaches the idle time period.

Hope you understand my issue. Please let me know what I am doing wrong here.

Regards,

Elango

 

 

 

Aug 6, 2009 at 4:26 PM

Also here is my web.config settings which i forgot to add in previous emails.

 <cachingConfiguration defaultCacheManager="MenuCacheManager">
    <cacheManagers>
      <add expirationPollFrequencyInSeconds="10" maximumElementsInCacheBeforeScavenging="1000"
        numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
        type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="MenuCacheManager" />
    </cacheManagers>
    <backingStores>
      <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Null Storage" />
    </backingStores>
  </cachingConfiguration>

 Regards,

Elango

Aug 7, 2009 at 9:44 AM

Hi,

The only way that the item in your cache might expire is someone might modified the file. Do you have other codes that does the modification to the said file?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 7, 2009 at 4:19 PM

Hi Valiant,

      I checked all those things before getting into the discussion. I didn't see anyone modified the file. But yesterday i made a local web application in my local pc and made it to run. You know almost 16 hrs still the cache is maintained. But analysing closely the only difference between my local machine and the test server is here in my local i installed enterprise application 4.1 which i downloaded from Microsoft site. Whereas in the test environment it has .net framework 3.5 and I copied those necessary enterprise dlls only to the test environment. Not sure whether i have to do a complete installation there using the downloaded executable from Microsoft site. Please confirm me on this. Rightr now i have the following dlls under bin folder in test environment

1. Microsoft.Practices.EnterpriseLibrary.Caching.dll, Microsoft.Practices.EnterpriseLibrary.Caching.xml

2. Microsoft.Practices.EnterpriseLibrary.Common.dll, Microsoft.Practices.EnterpriseLibrary.Common.xml

3. Microsoft.Practices.EnterpriseLibrary.Data.dll, Microsoft.Practices.EnterpriseLibrary.Data.xml

4. Microsoft.Practices.EnterpriseLibrary.Logging.dll, Microsoft.Practices.EnterpriseLibrary.Logging.xml

5. Microsoft.Practices.ObjectBuilder2.dll

6. Microsoft.Practices.Unity.dll

 

Regards,

Elango

 

Aug 10, 2009 at 8:56 AM

Hi,

AFAIK, copying the needed assemblies would work. What happens after the 16 hours of the cache intact? Does the problem persist after 16 hours in your local?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 10, 2009 at 11:50 PM

Looks like my local machine always persist the cache even after 16 hours. Only my testing and staging environment has this problem. Also i tried installing the enterpriselib setup exe on testing environment assuming that i didn't do an install there. But that also didn't help me. Do let me know what could be problem?

 

Regards,

Elango

Aug 11, 2009 at 2:36 AM

The main purpose of the installation is for the visual studio integration, copying the necessary assemblies and correctly referencing them would work, besides, I believe the expected behavior for this scenario is the same as with the other later versions of entlib.  How did you made sure that the file didn't get updated?  Did you just check the contents? You should base it in the Date Modified property of the file.  I did some testing and verified that the cache item with file dependency doesn't get removed during the scavenging process nor did it expire during idle time.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com