Frage

We're investigating moving to a distributed cache using Windows AppFabric. Our ASP.NET 4.0 application currently has a cache implementation that uses MemoryCache.

One key feature is that when items are added to the cache, a CacheItemPolicy is included that contains a ChangeMonitor:

 CacheItemPolicy policy = new CacheItemPolicy();
 policy.Priority = CacheItemPriority.Default;
 policy.ChangeMonitors.Add(new LastPublishDateChangeMonitor(key, item, GetLastPublishDateCallBack));

The change monitor internally uses a timer to periodically trigger the delegate passed into it - which is usually a method to get a value from a DB for comparison.

The policy and its change monitor are then included when an item is added to the cache:

Cache.Add(key, item, policy);

An early look at AppFabric's DataCache class seem to indicate whilst a Timespan can be included when adding items to cache, a CacheItemPolicy itself can't be.

Is there an another way to implement the same ChangeMonitor-type functionality in AppFabric. Notifications perhaps?

Cheers

Neil

War es hilfreich?

Lösung

There are only two hard problems in computer science: cache invalidation, naming things and off-by-one errors.
Phil Karlton

Unfortunately AppFabric has no support for this sort of monitoring to invalidate a cached item, and similarly no support for things like SqlCacheDependency.

However, AppFabric 1.1 brought in support for read-through and write-behind. Write-behind means that your application updates the cached data first rather than the underlying database, so that the cache always holds the latest version (and therefore the underlying data doesn't need to be monitored); the cache then updates the underlying database asynchronously. To implement read-through/write-behind, you'll need to create an object that inherits from DataCacheStoreProvider (MSDN) and write Read, Write and Delete methods that understand the structure of your database and how to update it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top