?
Solved

Cache dependency not working on one Vista PC

Posted on 2009-02-21
5
Medium Priority
?
588 Views
Last Modified: 2012-05-06
Hi, I am experiencing a VERY weird problem with which I have basically lost the whole day yesterday, and most of today.

On the Vista PC I use at work, the cache dependency on files is for some reasons not working as expected. The same application, when deployed on IIS6/Windows Server 2003 in a VMWare machine (on the same workstation), works fine, and I can see that the caching works exactly as expecting. Whenever I change the content of the files involved in the dependency, the cache is automatically refreshed as it should.

But this does not happen if I run the same application, with exactly the same settings, on Vista's own IIS7. I thought it could be yet another issue due to differences with IIS7, but I now think it is not, because I have tried the same application on my home's Vista, and the cache dependency on files is working fine as well.

I know the question might sound a bit weird, but could it be something related with the operating system or the file system? Otherwise that Vista is working fine every day.
The only weirdness is this: cache dependency on files does not work and the cache is not automatically invalidated / refreshed when I change the content of the files involved.

Just to exclude possible problems with this application (even though on my home pc's Vista it does work), I have also tried on both Vista machines to create an empty application, with just one webform containing a GridView which is bound to a dataset. The dataset is read from an XML file and the content cached.
On one Vista pc the dataset is correctly refreshed whenever the XML file changes, on the other Vista pc it is not.

Please help! The problem happens right on my work pc...
Many thanks in advance.
// nothing special here, just some code I used to reproduce the problem without the original application
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = (DataSet)Cache["pets"];
 
        if (ds == null)
        {
            string path = Server.MapPath("pets.xml");
            ds = new DataSet();
            ds.ReadXml(path);
            Cache.Insert("pets", ds, new CacheDependency(path));
            Trace.Warn("XML");
        }
        else
        {
            Trace.Warn("Cache");
        }
 
        GridView1.DataSource = ds;
        GridView1.DataBind();
 
    }

Open in new window

0
Comment
Question by:Sisupoika
  • 5
5 Comments
 

Author Comment

by:Sisupoika
ID: 23701208
I have just tried again, this time copying the simple test application to a folder shared from the virtual machine with Server 2K3, but still running the application from Vista's IIS and Visual Studio's integrated server.

Still same thing...
0
 

Author Comment

by:Sisupoika
ID: 23705328
Interesting... I've changed the code to use FileSystemWatcher  instead of CacheDependency, and nothing changes.
On the other Vista PC, it works as it did with CacheDependency, while on this one any changes to the files are not detected by ASP.NET regardless the method I use...
This is driving me crazy now...
    private void SetWatcher()
    {
       FileSystemWatcher watcher = new FileSystemWatcher();
       watcher.Path = Server.MapPath(".");
       Trace.Warn(Server.MapPath("."));
       watcher.Filter = "pets.xml";
       watcher.NotifyFilter = NotifyFilters.LastWrite; 
     
       // Add event handlers.
       watcher.Changed += new FileSystemEventHandler(OnChanged);
     
       // Begin watching.
       watcher.EnableRaisingEvents = true;
    }
 
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        HttpRuntime.Cache.Remove("pets");
    }

Open in new window

0
 

Author Comment

by:Sisupoika
ID: 23705389
Unbelievable!!! At last I found something! :D

I just tried to shrink one of the NTFS volumes on the disk, create a small (10MB) partition formatted with the old FAT, and copied the test application in there.

It WORKS! So it looks like it is a problem with NTFS for what I can tell..
If I find the reason and the possible fix I'll post it here for reference, but I hope somebody can help with this :)
0
 

Author Comment

by:Sisupoika
ID: 23706123
Another update... Following furher testing, it looks like the problem is the same regardless of the file system.
It does work, anyway, if I use FileSystemWatcher rather than CacheDependency.
But AFAIK I would need to run multiple instances of this class to watch multiple files that can be in different paths... and it does not sound efficient to me. Also, I would definitely like to understand why CacheDependency works fine on other PCs, including the other one with Vista as well.
0
 

Accepted Solution

by:
Sisupoika earned 0 total points
ID: 23706933
I have found a workaround for the time being.
Because FileSystemWatcher seems to be working also on that weird Vista, I have created a simple custom CacheDependency class which uses the FileSystemWatcher behind the scenes.
This also seems to work fine, however I won't close this question now because I still hope somebody could shed some light on this.
Apart from the reasons why FileSystemWatcher works on that Vista PC, while CacheDependency does not, I would also like to understand if there could be any performance implications or other, when using this custom class instead of the default CacheDependency.
I know I posted the question during the weekend, so hopefully I will hear from some experts from tomorrow on :)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Caching;
 
/// <summary>
/// Summary description for FilesCacheDependency
/// </summary>
public class FilesCacheDependency : CacheDependency
{
 
    public FilesCacheDependency(string[] files)
    {
        foreach (string file in files)
        {
            initWatcher(file);
        }
    }
 
    public FilesCacheDependency(string file)
    {
        initWatcher(file);
    }
 
 
    void watcher_Changed(object sender, FileSystemEventArgs e)
    {
        this.NotifyDependencyChanged(this, e);
    }
 
 
    void initWatcher(string filePath)
    {
        FileInfo fileInfo = new FileInfo(filePath);
 
        FileSystemWatcher watcher = new FileSystemWatcher(fileInfo.Directory.FullName);
 
        watcher.Filter = fileInfo.Name;
        watcher.EnableRaisingEvents = true;
        watcher.NotifyFilter = NotifyFilters.LastWrite;
 
        watcher.Changed += new FileSystemEventHandler(watcher_Changed);
 
        watcher.EnableRaisingEvents = true;
    }
 
}

Open in new window

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question