Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.02 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Does this code snippet use Repository or Adapter pattern?
  2. public interface ICacheProvider
  3. {
  4.   void Store(string key, object data);
  5.   void Destroy(string key);
  6.   T Get<T>(string key);
  7. }
  8.        
  9. public class CacheManager
  10. {
  11.   protected ICacheProvider _repository;
  12.   public CacheManager(ICacheProvider repository)
  13.   {
  14.       _repository = repository;
  15.   }
  16.  
  17.   public void Store(string key, object data)
  18.   {
  19.       _repository.Store(key, data);
  20.   }
  21.  
  22.   public void Destroy(string key)
  23.   {
  24.       _repository.Destroy(key);
  25.   }
  26.  
  27.   public T Get<T>(string key)
  28.   {
  29.       return _repository.Get<T>(key);
  30.   }
  31. }
  32.        
  33. public class SessionProvider : ICacheProvider
  34. {
  35.   public void Store(string key, object data)
  36.   {
  37.       HttpContext.Current.Cache.Insert(key, data);
  38.   }
  39.  
  40.   public void Destroy(string key)
  41.   {
  42.       HttpContext.Current.Cache.Remove(key);
  43.   }
  44.  
  45.   public T Get<T>(string key)
  46.   {
  47.       T item = default(T);
  48.       if (HttpContext.Current.Cache[key] != null)
  49.       {
  50.           item = (T)HttpContext.Current.Cache[key];
  51.       }
  52.       return item;
  53.   }
  54. }