473,671 Members | 2,550 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 3038
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**********@g mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.Cur rent.Server.Map Path("./xml/Menu.xml");

XmlDocument _xmlDoc = new XmlDocument();

// Get Menu.xml from cache or file
if(HttpContext. Current.Cache["MainMenuXM L"] == null)
{
_xmlDoc.Load(_p ath);
HttpContext.Cur rent.Cache["MainMenuXM L"] = _xmlDoc;

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

// Add Menu.xml to cache
HttpContext.Cur rent.Cache.Inse rt(
"MainMenuXm l",
_xmlDoc,
cd);
}
else
{
_xmlDoc = (XmlDocument)Ht tpContext.Curre nt.Cache["MainMenuXM L"];
}

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.Cur rent.Server.Map Path("./xml/Menu.xml");

XmlDocument _xmlDoc = new XmlDocument();

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

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

// Add Menu.xml to cache
HttpContext.Cur rent.Cache.Inse rt(
"MainMenuXm l",
_xmlDoc,
cd);
}
else
{
_xmlDoc = (XmlDocument)Ht tpContext.Curre nt.Cache["MainMenuXM L"];
}

return _xmlDoc;
}

Dec 9 '05 #4

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

Similar topics

0
1085
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 CacheDependency using the same fileserver. I have an ASP.NET application that needs to display filecounts for 300 different directories on my fileserver. I have a loop where I get each directory and determine the number of files. In order to...
0
1625
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 doc = new XmlDocument(); { ........ } string filePaths = { filePath, schemaPath }; CacheDependency dep = new CacheDependency(filePaths);
0
1081
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, It really Does Works (Code) CacheDependency dep=new CacheDependency(Server.MapPath
6
1772
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 ASP.NET and C# and need the expertese of individuals with more experience in these languages than I have. I may be completely off target as I thought this up very early in the morning. Here's the process as I see it: 1. InfoPath saves out the...
0
1156
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 file on the website and is show below. The delegate function 'refresher' only seems to fire in debug mode. The example below has been simplified because I actually want to retrieve values from the config.xml file when it changes but I need to get...
1
3681
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? Thanks!!!
0
1187
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 also take into account if a file gets deleted. I dont see it happening. Is this the desired functionality? Also, does the dependency for some reason keep a file handle open for the files int hat folder?
2
4308
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 System.Web.Caching.Cache. When i set up the file watchers and then create the cache dependency i receive an Exception (AccessViolationError - Attempted to read or write protected memory). I have included a the stack trace from the exception at the end of...
3
1841
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 dependency is triggered and my cache object is deleted. If I create a directory or delete another file in that same directory then the Cache is not bothered. My CacheDependency specifies the full and proper file name and not just the...
0
8483
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6237
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.