/// <summary> /// Gets the shared instance of a data model. /// </summary> /// <typeparam name="T">Type of data model to retrieve.</typeparam> /// <param name="id">Unique identifier of model to retrieve.</param> /// <returns>Requested model, <c>null</c> if not found.</returns> public T Get <T>(int id) where T : DataModelBase, new() { T item; DataModelCache cache; if (_items.TryGetValue(typeof(T), out cache)) { item = cache.TryGet(id) as T; if (item != null) { return(item); } } else { cache = new DataModelCache(); _items[typeof(T)] = cache; } item = GetCopy <T>(id); if (item == null) { return(null); } item = (T)cache.TryCache(id, item); return(item); }
/// <summary> /// Caches the specified item using the provided unique identifier. /// </summary> protected void Cache <T>(int id, T item) where T : DataModelBase { DataModelCache cache; if (!_items.TryGetValue(typeof(T), out cache)) { cache = new DataModelCache(); _items[typeof(T)] = cache; } cache.Cache(id, item); }
internal T TryCache <T>(int id, T item) where T : DataModelBase { DataModelCache cache; if (!_items.TryGetValue(typeof(T), out cache)) { cache = new DataModelCache(); _items[typeof(T)] = cache; } return((T)cache.TryCache(id, item)); }
public static void ClearCache(this HttpContextBase context) { DataModelCache caching = new DataModelCache(context); caching.Clear(); }
public static Object GetCacheValue(this HttpContextBase context, String keyName) { DataModelCache caching = new DataModelCache(context); return(caching[keyName]); }
public static void SetCacheValue(this HttpContextBase context, String keyName, Object value) { DataModelCache caching = new DataModelCache(context); caching[keyName] = value; }
public DataModelCacheDebugView(DataModelCache cache) { _cache = cache; }