Another possibility I have become aware of from another post is the cache object. From what I read it can be used interchangably with an Application variable. What are the benefits and disadvantages of each approach? I read where a cache object has automatic data locks where they have to be explicitely set with an appliction variable but this can be a disadvantage if they are not needed. My catalog can not be changed by any user and would only be changed when I update a new XML file so data locks wouldn't do me any good and only add to overhead.
With either method, how would I get the application to reload the data when the xml file is updated?
I think I may have just found the answer but would like verification. The cache object can be set to expire when the xml file is replaced and can then have a callback function reload it with the new data. Not sure how it could be done with an application variable. In C#:
Cache.Insert ""myKey", myValue,
new Cache\Dependency(Server.MapPath("mysml.XML")),
null,
Cache.NoSlidingExpiration);TimeSpan.FromSeconds(30 ),
CacheItemPriority.High, onRemove);
If I leave out the onremove callback function will it automatically reload when needed or will I have to add functionality to my code?
I suspect cache may be a little slower with the automated datalocks and memory management but the difference would be likely measured in milliseconds and thus won't make much difference overall compared with bandwidth issues unless the data is being accessed repeatedly in the application (would creating a reference to the cache object and then casting that reference to a dataset get away from accessing the cache for each call to the dataset?).
Either would be better than loading an xml file for each page and infinitely better than loading the data from a database for each view. I am thinking now that the Cache's memory management features would make it the best bet.
Sorry for being so long winded, just trying to work things out in my mind and consider all factors so i can come up with the best option.
|