public interface ICacheable<TK,TV>
{
TV Get(TK key);
void Add(TK key, TV val);
}
public abstract class BaseCache<TK, TV>
{
protected static Dictionary<Guid, Dictionary<TK, TV>> data = new Dictionary<Guid, Dictionary<TK, TV>>();
private Guid StorageNameSpage;
protected BaseCache(Guid storageNameSpage)
{
StorageNameSpage = storageNameSpage;
}
protected BaseCache()
{
StorageNameSpage = Guid.NewGuid();
}
public TV Get(TK key)
{
return data[StorageNameSpage][key];
}
public void Add(TK key, TV val)
{
data.Add(....);
}
}
2 different ways to implement it:
"mulityTon" or what ever you want to call it.
public class KeyValCacheStorage<TK, TV> : BaseCache<TK, TV>, ICacheable<TK, TV>
{
}
SingleTome
public class KeyValCacheStorageSingleTon<TK, TV> : BaseCache<TK, TV>, ICacheable<TK, TV>
{
private static Guid storageNameSpage = Guid.NewGuid();
public KeyValCacheStorageSingleTon():base(storageNameSpage)
{
}
}
usage:
KeyValCacheStorageSingleTon<string, string> storageSingleTon1 = new KeyValCacheStorageSingleTon<string, string>();
storageSingleTon1.Add("storageSingleTon1", "KeyValCacheStorageSingleTon");
storageSingleTon1.Add("bla", "yada");
KeyValCacheStorageSingleTon<string, string> storageSingleTon2 = new KeyValCacheStorageSingleTon<string, string>();
storageSingleTon2.Add("storageSingleTon2", "KeyValCacheStorageSingleTon2");