using System; using System.Configuration; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Web; using System.Web.Caching; using System.Xml.Linq; using System.Xml.Serialization; namespace Neo.Afx.Common { /// /// CacheContext wrapper /// public class CacheContext : ICacheContext { ICacheContext _cacheContext; /// /// Cache container to be used /// private ICacheContext CacheContextContainer { get { if (_cacheContext == null) { try { if (ConfigurationManager.AppSettings["RedisConnection"] != null && ConfigurationManager.AppSettings["RedisConnection"] != "") { _cacheContext = new CacheContextRedis(); } else { _cacheContext = new CacheContextWeb(); } } catch { //silent fall trhough if error creating cache //todo add tracing return null; } } return _cacheContext; } } /// /// Default constructor /// public CacheContext() { } /// /// Get the cached value based on a specified key /// /// /// /// public T Get(string key) { try { return CacheContextContainer.Get(key); } catch { //silent fall trhough if error retrieving from cache //todo add tracing _cacheContext = null; return default(T); } } /// /// Set the cached value /// /// /// /// public void Set(string key, object value, int cacheExpirationMinutes) { try { CacheContextContainer.Set(key, value, cacheExpirationMinutes); } catch { //silent fall trhough if error retrieving from cache //todo add tracing _cacheContext = null; } } /// /// Remove a cached value /// /// public void Remove(string key) { try { CacheContextContainer.Remove(key); } catch { //silent fall trhough if error retrieving from cache //todo add tracing _cacheContext = null; } } /// /// Clear the cache /// public void Clear() { try { CacheContextContainer.Clear(); } catch { //silent fall trhough if error retrieving from cache //todo add tracing _cacheContext = null; } } } }