views:

20

answers:

1

We are thinking about using the enterprise library caching framework in our asp.net 3.5 application to store small datatables of our most hit products.

Is there a way to write an outside process, like a console application, to remove these datatables, if needed? For example, a client can come in and update the data for a product, which will make the datatable stored in cache out of date. When this happens, I would like an outside application go into the cache and remove or even update the cache with the new data.

+1  A: 

I can think of two approaches to remove cache items from out of process.

The first is to use a FileDependency when adding items to your cache. When you want to expire a cache item then modify the file.

DataTable books = GetTopBooks();

ICacheManager cacheManager = CacheFactory.GetCacheManager();
cacheManager.Add("books", books, CacheItemPriority.NotRemovable, new BookCacheRefreshAction(), 
    new FileDependency("books.xml"));

Then an external process can expire your DataTable by modifying the appropriate file on disk (in this case books.xml). You can also configure an ICacheItemRefreshAction to refresh the cache (e.g. from the database) when it is expired.

If for some reason the file based approach is not sufficient then the second approach would be to create a custom interface that could be invoked by the out of process application. e.g. create a web service which will remove items from the cache and potentially refresh the cache item.

Tuzo