.NET: caching in a database or file system using CacheDependency

I would like to know if there is a way to cache the .NET cache in a table or database file, not in the cache in memory, but also use the CacheDependency infrastructure. I think the Enterprise Library can do this, but I would prefer something simpler if possible.

To explain, I want cached data to be placed in an SQL table or in a file on disk, and not in memory. Then I want to specify a CacheDependency, which can be SqlCacheDependency or CacheDependency in a file or AggregateCacheDependency.

The reason is because I am doing intensive calculations based on xml documents (which change once a day or so). The results of these calculations are stored in memory. However, if the website is reset, the cache is lost. It would be nice to have a backup cache in the database.

-1
source share
1 answer

Use SqlCacheDependency . You need to manually manage the target data manually, but you may have a cache dependency that is automatically invalid when the target table changes.

EDIT:

Yes, you can use the caching block in the corporate library to have a cache provider that stores items in the database using a data access block, which is an alternative to ASP.NET. This is probably the best solution, despite a higher learning curve.

I think SqlCacheDependency simpler because you use the ASP.NET cache to first save the local memory version for faster processing, returning to the database level when the local level has no element available. Here is an example of what I mean:

  • Your web application calls GetXmlDocument(string key) to get something to work with

  • The method first checks the ASP.NET cache for the element - if the element exists, fine, you return it

  • If the element does not exist, then you check the database for the presence of the element - if the element exists, you re-populate the local cache element using SqlCacheDependency in the database table and return the XML data

  • If the element also does not exist in the database, you retrieve the XML data from the source, wherever the primary source is located, re-populate the database, SqlCacheDependency local cache element with SqlCacheDependency in the table, and return the XML data

This gives you a standalone two-tier cache.

+1
source

All Articles