CS中的缓存类,保证都看的懂

本文介绍了一个名为CSCache的缓存管理类,该类提供了多种缓存操作的方法,如插入、获取、移除缓存项等,并且支持设置缓存依赖和缓存时间。文章展示了如何通过不同的参数配置来实现灵活的缓存管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         什么也不说了,谁都看的懂....


ContractedBlock.gifExpandedBlockStart.gif
ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
InBlock.gif    
/// Summary description for CSCache.
ExpandedBlockEnd.gif    
/// </summary>

None.gif    public class CSCache
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private CSCache()dot.gif{}
InBlock.gif
InBlock.gif        
//>> Based on Factor = 5 default value
InBlock.gif
        public static readonly int DayFactor = TCache.DayFactor;
InBlock.gif        
public static readonly int HourFactor = TCache.HourFactor;
InBlock.gif        
public static readonly int MinuteFactor = TCache.MinuteFactor;
InBlock.gif        
public static readonly double SecondFactor = TCache.SecondFactor;
InBlock.gif
InBlock.gif        
public static void ReSetFactor(int cacheFactor)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.ReSetFactor(cacheFactor);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Removes all items from the Cache
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void Clear()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Clear();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void RemoveByPattern(string pattern)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.RemoveByPattern(pattern);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Removes the specified key from the cache
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="key"></param>

InBlock.gif        public static void Remove(string key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Remove(key);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Insert the current "obj" into the cache. 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="key"></param>
ExpandedSubBlockEnd.gif        
/// <param name="obj"></param>

InBlock.gif        public static void Insert(string key, object obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key, obj, 
1);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Insert(string key, object obj, CacheDependency dep)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key, obj, dep);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Insert(string key, object obj, int seconds)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key, obj, seconds);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Insert(string key, object obj, int seconds, CacheItemPriority priority)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key, obj, seconds, priority);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Insert(string key, object obj, CacheDependency dep, int seconds)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key, obj, dep, seconds);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Insert(string key, object obj, CacheDependency dep, int seconds, CacheItemPriority priority)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Insert(key,obj,dep,seconds,priority);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void MicroInsert (string key, object obj, int secondFactor) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.MicroInsert(key, obj, secondFactor);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Insert an item into the cache for the Maximum allowed time
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="key"></param>
ExpandedSubBlockEnd.gif        
/// <param name="obj"></param>

InBlock.gif        public static void Max(string key, object obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Max(key, obj);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Max(string key, object obj, CacheDependency dep)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif                TCache.Max(key, obj, dep);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Insert an item into the cache for the Maximum allowed time
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="key"></param>
ExpandedSubBlockEnd.gif        
/// <param name="obj"></param>

InBlock.gif        public static void Permanent(string key, object obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TCache.Permanent(key, obj);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Permanent(string key, object obj, CacheDependency dep)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif                TCache.Permanent(key, obj, dep);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static object Get(string key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return TCache.Get(key);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Return int of seconds * SecondFactor
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static int SecondFactorCalculate(int seconds)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// Insert method below takes integer seconds, so we have to round any fractional values
InBlock.gif
            return TCache.SecondFactorCalculate(seconds);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif    }


我看这样也行

None.gif    public class CSCache:TCache
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
ExpandedBlockEnd.gif    }

不过,如果TCache不可以继承的话,而我们又想偷懒的话,以后就不写代码,然后哪别人的代码,然后就像上面这样干...把命名空间改了就好,高效率操作啊:)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值