473,511 Members | 16,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CacheDependency with File Dependency

TJO
My asp.net 1.1 app is loading an xml file into cache so that subsequent
calls for the xml file will not be pulled from the file system but from
the cache instead.

My method for loading the xml does the following:

1) Checks the cache to see if it is there
2) If not in cache load xml file, else pull it from cache
3) Creates new CacheDependency object using the full path of the xml
and current datetime
3) Inserts xml into cache using the CacheDependency object

This is working fine but when I change the xml file the application
does not reload the file but keeps pulling it from cache!

Why does it not recognize my file being changed?

Dec 8 '05 #1
3 3020
with no sample code, its hard to know what you did wrong. the file
dependency works fine (does require ntfs filesystem).

-- bruce (sqlwork.com)
"TJO" <Ti**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
My asp.net 1.1 app is loading an xml file into cache so that subsequent
calls for the xml file will not be pulled from the file system but from
the cache instead.

My method for loading the xml does the following:

1) Checks the cache to see if it is there
2) If not in cache load xml file, else pull it from cache
3) Creates new CacheDependency object using the full path of the xml
and current datetime
3) Inserts xml into cache using the CacheDependency object

This is working fine but when I change the xml file the application
does not reload the file but keeps pulling it from cache!

Why does it not recognize my file being changed?

Dec 8 '05 #2
TJO
Here you go:
public static XmlDocument _GetMenuXML()
{
string _path =
HttpContext.Current.Server.MapPath("./xml/Menu.xml");

XmlDocument _xmlDoc = new XmlDocument();

// Get Menu.xml from cache or file
if(HttpContext.Current.Cache["MainMenuXML"] == null)
{
_xmlDoc.Load(_path);
HttpContext.Current.Cache["MainMenuXML"] = _xmlDoc;

// Cache is dependent upon changes to the Menu.xml file
CacheDependency cd = new CacheDependency(_path,DateTime.Now);

// Add Menu.xml to cache
HttpContext.Current.Cache.Insert(
"MainMenuXml",
_xmlDoc,
cd);
}
else
{
_xmlDoc = (XmlDocument)HttpContext.Current.Cache["MainMenuXML"];
}

return _xmlDoc;
}

Dec 8 '05 #3
TJO
Previous code had error but now the cache evaluation is always false.
public static XmlDocument _GetMenuXML()
{
string _path =
HttpContext.Current.Server.MapPath("./xml/Menu.xml");

XmlDocument _xmlDoc = new XmlDocument();

// Get Menu.xml from cache or file
if(HttpContext.Current.Cache.Get("MainMenuXML") == null)
{
_xmlDoc.Load(_path);

// Cache is dependent upon changes to the Menu.xml file
CacheDependency cd = new CacheDependency(_path);

// Add Menu.xml to cache
HttpContext.Current.Cache.Insert(
"MainMenuXml",
_xmlDoc,
cd);
}
else
{
_xmlDoc = (XmlDocument)HttpContext.Current.Cache["MainMenuXML"];
}

return _xmlDoc;
}

Dec 9 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1082
by: Nick | last post by:
I am getting the following error when creating a new CacheDependency object: Failed to start monitoring changes to '\\server\share\dir49' This error happens after 48 successful instantiations of...
0
1618
by: Keith | last post by:
Hi. I've developed an ASP.NET web service that uses an xml file to store configuration settings. I'm creating a cache dependency based on the xml file and its schema, like this... XmlDocument...
0
1071
by: Brian | last post by:
Hi~ I use ASP.NET (framework 1.1 and windows 2003 server-) Cache works well but it never expires with the CacheDependency object and Expire Time Setting. In Windows XP, as far as I remember,...
6
1761
by: Greg Collins [MVP] | last post by:
For background, please refer to my original thread: http://groups.google.com/groups?selm=efe5w7tYEHA.3112%40tk2msftngp13.phx.gbl I've thought of a potential way around the issue, but I'm new to...
0
1151
by: Dave S | last post by:
Hi, I'm trying to use cachedependency to refresh a variable when a config file in the web application changes, but it doesn't seem to work no matter what I do. The code is in the global.asax...
1
3671
by: Diffident | last post by:
Howdy, How can I set the CacheDependency to an Oracle table? I have come across SqlDependency class for using the CacheDependency to an SQL server table but not Oracle. Any pointers? ...
0
1184
by: Weston Weems | last post by:
Hello... I insert cache items in a method with a dependency and a callback reference. I set a breakpoint in the callback, and it does get fired when I add new file into the folder, but I want to...
2
4294
by: daniel | last post by:
Hi, I am developing an application that requires me to set up file system watchers on directories on a network drive, as well as set up CacheDependencies in the same location for my...
3
1835
by: Dave | last post by:
Using ASP.Net 2.0 on Vista with IIS6, if I set a CacheDependency on a file into a Cache entry that I insert and then delete a subdirectory in the same directory that the file is located in then my...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.