zoukankan      html  css  js  c++  java
  • 批量更新memcached缓存

    假如系统里有3类数据company,user,product

    利用维护版本号version的方式达到批量更新缓存的效果

    memcache.Add("company",cversion);记录company数据的版本

    memcache.Add("user",uversion);记录user数据的版本

    memcache.Add("product",pversion);记录product数据的版本

    更新或删除数据时维护版本

    memcache.Add("company",cversion+1);

    查询数据时 company+type+version就是所要获取数据的key

    key=memcache.get("company");

    memcache.get("company"+type+key);

            public IEnumerable<Company> GetList(int count)
            {            
                var version=DistCache.Get("company");
                if (version == null)
                {
                    DistCache.Add("company", 0);
                    version = 0;
                }         
                var key = "company_list_" + count + "_version" + version;
                var obj = DistCache.Get(key);
                if (obj == null)
                {
                    var data = _dal.GetList(count);
                    DistCache.Add(key, JsonConvert.SerializeObject(data), true);
                    return data;
                }
                return JsonConvert.DeserializeObject<IEnumerable<Company>>(obj.ToString());
                
            }
    
            public int UpdateCompany(Company info)
            {
                var version = DistCache.Get("company");
    
                if (version == null)
                {
                    DistCache.Add("company", 0);
                    version = 0;
                }
                else
                {
                    version = Convert.ToInt32(version) + 1;
                    DistCache.Add("company", version);
                }
                return _dal.Update(info);
            }
  • 相关阅读:
    ranorex
    vue.js
    逻辑思维
    laravel-luntan
    python学习--基础
    git
    Laravel-高级篇-Auth-数据迁移-数据填充
    Laravel-高级篇-Artisan
    Laravel-表单篇-零散信息
    Laravel-表单篇-controller
  • 原文地址:https://www.cnblogs.com/isfish/p/4414116.html
Copyright © 2011-2022 走看看