1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
class Cache{
private static Cache _theUniqueInstance = null;
private Hashtable _data = new Hashtable() ;
private Cache(){}
public static Cache GetInstance(){
if(_theUniqueInstance == null) return _theUniqueInstance = new Cache();
else return _theUniqueInstance;
}
public static object Get(string key){
this.GetInstance();
if (_data.ContainsKey(key)) return _data[key];
return null;
}
public static void Set(string key, object item){
this.GetInstance();
if (_data.ContainsKey(key)) _data[key] = item;
else _data.Add(key, item);
}
public static void Clear(string key){
this.GetInstance();
if (_data.ContainsKey(key)) _data.Remove(key);
}
} |
Partager