1

I'm working on an open source where I need to populate a dictionary from reading values from multiple xml files and whenever any of the xml file changes I have to update the dictionary. Since there are multiple files I thought of using FileSystemWatcher. Is this a good idea? or I've to go with ASP.NET cache with file dependency? I'm not sure how ASP.NET cache helps me in the case of multiple files.

Note: I've implemented a locking mechainsm while updating the dictionary so threading won't be an issue in the case of updating dictionary.

4
  • FileSystemWatcher is not easy to work with. Whenever I've tried to use it I've ended up using a timer to scan the directory for updated files instead. That is much more reliable. Commented Oct 12, 2012 at 11:40
  • @MartinLiversage Do you have idea how I can use ASP.NET cache with dependency on multiple files? Commented Oct 12, 2012 at 11:43
  • 1
    I think I've to use AggregateCacheDependency codeidol.com/csharp/csharpckbk2/Web/… Commented Oct 12, 2012 at 11:54
  • No, not really, that is why I only wrote a comment because I can't provide an answer to your question. Commented Oct 12, 2012 at 12:01

1 Answer 1

2

For creating dependencies for multiple files you can use the AggregateCacheDependency like this:

CacheDependency[] depArray = new CacheDependency () 
{
  new CacheDependency(Server.MapPath("foo.txt")),
  new CacheDependency(Server.MapPath("bar.txt"))
};

AggregateCacheDependency aggDep = new AggregateCacheDependency();
aggDep.Add(depArray);

Cache.Insert("key", value, aggDep);
Sign up to request clarification or add additional context in comments.

1 Comment

On Cache.Insert there are two overloads for Item update and delete callback msdn.microsoft.com/en-us/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.