DevCache轻量级缓存组件
DevCache为MadAdmin开发平台的缓存组件,暂时包括文件缓存,内存缓存,MemCached,Redis四部分,代码都比较简单,有问题可自行修改源码解决。
详细API请参照源码,注意事项如下:
1.每种缓存都有自己的一些特殊配置参数。
2.由于每种缓存都有自己的特色,而在之前的项目中也是多种缓存配合使用,所以并没有提取公共接口出来。
3.以后可能会加入Tokoy Tyrant支持。
4.在缓存设置中建议设置KeyPrefix参数,建议形式为:“唯一项目标识.版本号.”,需要清除缓存时,版本号加1即可。
5.开发期间有时需要看到即时效果,可设置IsCache=”false”,使缓存失效。
//文件缓存 FileCache cache1=FileCacheClient.GetInstance("Default"); //内存缓存 MemoryCache cache2=MemoryCacheClient.GetInstance(); //MemCached MemcachedClient cache = MemcachedClient.GetInstance("Default"); //Redis RedisClient client = RedisClientFactory.GetInstance("Default");
Web.config
< ?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <section name="DevCache" type="DevCache.DevCacheSectionHandler,DevCache" /> </configsections> <devcache> <filecached> <setting IsCache="true" /> <add name="Default" FileCachePath="/FileCache/" KeyPrefix="" /> </filecached> <memorycached> <setting IsCache="true" IntervalMinutes="1" ScavangeMinutes="60" MaxCount="1000000" MaxSize="100*1024" /> <add name="Default" KeyPrefix="" /> </memorycached> <memcached> <setting IsCache="true" SendReceiveTimeout="2000" MinPoolSize="5" MaxPoolSize="10" /> <add name="Default" Hosts="127.0.0.1:11211" KeyPrefix="Default.001." /> <add name="Second" Hosts="127.0.0.1:11211,127.0.0.1:11212" KeyPrefix="Second.001." /> <add name="MyOther" Hosts="server1.example.com:12345, server2.example.com:12345, server3.example.com:12345" KeyPrefix="" /> </memcached> <redis> <setting IsCache="true" SendTimeout="-1" /> <add name="Default" Host="127.0.0.1" Port="6379" DefaultDB="0" /> <add name="Second" Host="127.0.0.1" Port="6379" DefaultDB="1" /> </redis> </devcache> </configuration>