
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 1.02 KB | hits: 11 | expires: Never
Does this code snippet use Repository or Adapter pattern?
public interface ICacheProvider
{
void Store(string key, object data);
void Destroy(string key);
T Get<T>(string key);
}
public class CacheManager
{
protected ICacheProvider _repository;
public CacheManager(ICacheProvider repository)
{
_repository = repository;
}
public void Store(string key, object data)
{
_repository.Store(key, data);
}
public void Destroy(string key)
{
_repository.Destroy(key);
}
public T Get<T>(string key)
{
return _repository.Get<T>(key);
}
}
public class SessionProvider : ICacheProvider
{
public void Store(string key, object data)
{
HttpContext.Current.Cache.Insert(key, data);
}
public void Destroy(string key)
{
HttpContext.Current.Cache.Remove(key);
}
public T Get<T>(string key)
{
T item = default(T);
if (HttpContext.Current.Cache[key] != null)
{
item = (T)HttpContext.Current.Cache[key];
}
return item;
}
}