Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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;
        }
Example #7
0
 public DataModelCacheDebugView(DataModelCache cache)
 {
     _cache = cache;
 }