作者:夜夜0603 | 来源:互联网 | 2022-12-26 12:24
///
/// 系统缓存
///
public class Caching
{
///
/// 缓存对象
///
public static readonly Caching Cache = new Caching();
private System.Collections.Hashtable _cache;
private Caching()
{
_cache = new Hashtable();
}
///
/// 获取/设置缓存对象
///
/// 键值
///
public object this[string key]
{
get
{
//获取缓存对象
return (_cache[key]);
}
set
{
if (_cache.Contains(key))
{
//缓存中已存在该键,先删除该键,然后设置新的键及对象
Remove(key);
}
//添加缓存对象
_cache.Add(key, value);
}
}
///
/// 清除缓存中指定键对象
///
/// 键值
public void Remove(string key)
{
_cache.Remove(key);
}
///
/// 清除缓存中所有对象
///
public void RemoveAll()
{
_cache.Clear();
}
}