If there are 3 types of data in the system company,user,product
The effect of batch update cache is achieved by maintaining version number version
Memcache. ADD ("Company", Cversion); record the version of company data
Memcache. ADD ("User", uversion); record the version of the user data
Memcache. ADD ("Product", pversion); record the version of the product data
Maintain versions when updating or deleting data
Memcache. ADD ("Company", cversion+1);
Company+type+version is the key to get the data when querying the data
Key=memcache.get ("Company");
Memcache.get ("Company" +type+key);
PublicIenumerable<company> GetList (intcount) { varVersion=distcache.get (" Company"); if(Version = =NULL) {Distcache.add (" Company",0); Version=0; } varKey ="Company_list_"+ Count +"_version"+version; varobj =Distcache.get (key); if(obj = =NULL) { vardata =_dal. GetList (count); Distcache.add (Key, Jsonconvert.serializeobject (data),true); returndata; } returnJsonconvert.deserializeobject<ienumerable<company>>(obj. ToString ()); } Public intUpdatecompany (company info) {varVersion = 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); }
Bulk Update memcached Cache