Question for all Cache Gurus
I have a page in my website that pulls content for anewsletter from a SQL Server 2000 database using a SqlDataSource and aFormView. I add a new newsletter every week. Other than that weekly addition,no changes are really ever needed or made to the data. Scott Gu says everyapplication can and should make use of caching and I would like to add somekind of caching to improve the performance of this page. I have read about SqlCacheDependency with SQL2000, but if I understand it correctly, it will poll the database for changesevery x seconds, an expensive operation that I just don't need; the data onlychanges once a week. I've seen some code examples using DataSets and the CacheAPI but I'm really just looking for a simple, mostly declarative solution using theSqlDataSource. Theoretically, I wouldlike the data cached forever until I insert a new item. I have set thefollowing cache-related properties on my SqlDataSource as follows:
EnableCaching = True
DataSourceMode = DataSet
CacheDuration = Infinite
CacheExpirationPolicy = Absolute
Setting these properties seems to work great for caching thedata but how do I programmatically invalidate the cache when a new item isinserted? I have a separate admin page with a FormView that I use to insert thenewsletter each week. Is there some kind of code that I could put in theItemInserted event that would invalidate the cache so that the new item will bedisplayed and then cached? I don't have any experience with caching; where am I going wrong? Are my expectations unrealistic? Thank you in advance to anyone who can shed somelight on this issue.
The best way to do this is by using filebased cache dependency. So when ever any change happens to the file cache gets invalidated. check out the below link.
http://www.eggheadcafe.com/articles/20030716.asp
In this Peter used SQL trigger to update the file, but for your requirment I would suggest, as soon as upload a new news letter through admin portal, make change to this dependency file, thats it cache gets invalidated and any new requests gets the new data.
No comments:
Post a Comment