zoukankan      html  css  js  c++  java
  • 负载均衡环境下缓存处理


    深入学习
    Enterprise Library for .NET Framework 2.0Cache机制——分析篇
    ,
    这篇文章介绍了很多Caching方面的内容,我就不详细说了,我这里主要说一个最近在做的一个Cache模块的Web Farm环境,也就是负载均衡环境下处理缓存的处理途径。主要思路如下:将缓存的过期策略使用依赖文件,就是缓存项依赖于文件,缓存发生改变,就修改依赖文件,一般就是将文件的日期修改。

    可以通过使用共同的缓存依赖文件来完成. CacheManager对象Add方法的public void Add(string key, object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, params ICacheItemExpiration[] expirations)

    ICacheItemExpiration有一个实现FileDependency.  ICacheItemRefreshAction 接口可以用来实现缓存依赖的文件发生改变完成缓存过期后的重新获取数据,以此来达到各台服务器的Cache同步.
    例如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 upon

    // the removal reason (e.g. refresh the cache with the item).

    if (removalReason != CacheItemRemovedReason.Removed)

            {

     

      }

        }

      }

    欢迎大家扫描下面二维码成为我的客户,为你服务和上云

  • 相关阅读:
    遇到的两个问题
    项目分析(map复习)
    while小问题
    二级指针
    映射文件实现进程通信
    struct {0}初始化
    用boost共享内存实现进程通信的例子
    mongo二维数组操作
    项目分析(channelid是如果产生的)
    string为什么可以写入共享内存
  • 原文地址:https://www.cnblogs.com/shanyou/p/378633.html
Copyright © 2011-2022 走看看