synchronization of cache using file dependency not working

Asked By shweta chandaliya
02-Feb-10 07:49 AM
Earn up to 0 extra points for answering this tough question.
Our application is deployed in the web farm. Web farm has 2 servers. We need to synchronize the cache objects between these 2 server. For this, I am using a cache dependency on a text file, like below;

Cache.Insert("articlespostHashtable", articledata.PostHashtable, new System.Web.Caching.CacheDependency(Server.MapPath(depFileName)), System.Web.Caching.Cache.NoAbsoluteExpiration,
                    System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);

And whenever the data is updated, I modify the text file so that my cache is invalidated.

using (StreamWriter sw = new StreamWriter(Server.MapPath(ConfigurationManager.AppSettings["CacheSynchDepFile"].ToString()), true))
                {
                    sw.Write(DateTime.Now.ToString() ;
                }

The text file i am storing on a shared folder which is on the server1. The other server Server2 also has the access to this file through the shared folder.

This thing is working properly if the data is updated on the Server1 but not working properly if the data is getting updated from Server2. It do not refreshes the data immediatly and takes few minutes. Please guide me for the same.


  re: synchronization of cache using file dependency not working

Huggy Bear replied to shweta chandaliya
02-Feb-10 08:06 AM
Sounds weird. But try accessing the shared folder manually from Server2 and check how much time it takes. I couldn't think of anyother stuff apart from netwrok related latency.

  re: re: synchronization of cache using file dependency not working

shweta chandaliya replied to Huggy Bear
02-Feb-10 08:21 AM
Thanks a lot for such a quick reply. I will check what you said and get back to you.

  re: synchronization of cache using file dependency not working

Sandra Jain replied to shweta chandaliya
02-Feb-10 08:46 AM
Take  a closer look at the service methods implemented for caching used in this link that may be of help for your problem

http://msdn.microsoft.com/en-us/magazine/cc188799.aspx
  re: synchronization of cache using file dependency not working
Scott replied to shweta chandaliya
07-Apr-10 08:42 AM
Hi, did you got to the bottom of this? We are having the exact same issue. Only one server ever seems to respond to the file change?
  re: re: synchronization of cache using file dependency not working
shweta chandaliya replied to Scott
08-Apr-10 04:59 AM
No, the problem is still there. I am thinking of implemeting sql dependency, if it works i'll let you know.
  re: re: re: synchronization of cache using file dependency not working
Scott replied to shweta chandaliya
08-Apr-10 05:04 AM
I found my issue. One of the servers had "File Change Notifications" turned off so the file wasn't actually being monitored for changes - it doesn't throw an error, just doesn't work.

Also, check this out:

http://support.microsoft.com/kb/281253

Create New Account