Learn more about Enterprise Library. net Framework 2.0 cache mechanism-analysis article, this article introduces a lot of caching content, I will not detail, I will mainly talk about the web farm environment of a recently developed cache module, that is, the way to process the cache in the Server Load balancer environment. The main idea is as follows: the cache Expiration Policy uses dependent files, that is, the cache items depend on files. If the cache changes, the dependent files are modified. Generally, the file date is modified.
Public void add (string key, object value, cacheitempriority scavengingpriority, inclurefreshaction, Params icacheitemexpiration [] expirations) of the. cachemanager object add method can be completed by using a common cache dependent file)
Icacheitemexpiration has a filedependency. icacheitemrefreshaction interface that can be used to implement cache dependent file changes, and re-obtain data after cache expiration to achieve cache synchronization for each server.
For example, primitivescache. Add (product. productid, product, enternewitemform. Priority, new productcacherefreshaction (), new filedependency ("\ server06 \ dependencyfile.txt "));
[Serializable]
Public class productcacherefreshaction: icacheitemrefreshaction
{
Public void refresh (string key, object expiredvalue, cacheitemremovedreason removalreason)
{
// Item has been removed from cache. Perform desired actions here, based
// The removal reason (e.g. Refresh the cache with the item ).
If (removalreason! = Cacheitemremovedreason. removed)
{
}
}
}