Exemple #1
0
        /// <summary>
        /// Try to get a stored object.
        /// </summary>
        /// <typeparam name="T">Type of stored item.</typeparam>
        /// <param name="model">Key model.</param>
        /// <param name="value">Stored value.</param>
        /// <returns>Stored item as type.</returns>
        public bool TryGet <T>(KeyModel model, out T value)
        {
            // Set namespace of model
            model.Namespace = Namespace;

            // Call actual Cache Service
#if DEBUG
            var step = MiniProfiler.Current.Step(string.Format("CacheService: TryGet {0} {1} {2}", model.CacheType, model.Key, model.GetValuesKey()));

            try
            {
#endif
            return(CacheService.TryGet(model, out value));

#if DEBUG
        }
        finally
        {
            if (step != null)
            {
                step.Dispose();
            }
        }
#endif
        }
Exemple #2
0
        /// <summary>
        /// Set an item in the cache under a unique key.
        /// </summary>
        /// <typeparam name="T">Type of item.</typeparam>
        /// <param name="model">Key model.</param>
        /// <param name="o">Item to be stored in cache.</param>
        /// <param name="timeToLive"></param>
        public void Set <T>(KeyModel model, T o, TimeSpan timeToLive)
        {
            // Set namespace of model
            model.Namespace = Namespace;

            // Call actual Cache Service
#if DEBUG
            var step = MiniProfiler.Current.Step(string.Format("CacheService: Set {0} {1} {2}", model.CacheType, model.Key, model.GetValuesKey()));

            try
            {
#endif
            CacheService.Set(model, o, timeToLive);
#if DEBUG
        }
        finally
        {
            if (step != null)
            {
                step.Dispose();
            }
        }
#endif
        }
Exemple #3
0
        /// <summary>
        /// Remove an item from the cache.
        /// </summary>
        /// <param name="model">Key model.</param>
        public void Remove(KeyModel model)
        {
            // Set namespace of model
            model.Namespace = Namespace;

            // Call actual Cache Service
#if DEBUG
            var step = MiniProfiler.Current.Step(string.Format("CacheService: Remove {0} {1} {2}", model.CacheType, model.Key, model.GetValuesKey()));

            try
            {
#endif
            CacheService.Remove(model);
#if DEBUG
        }
        finally
        {
            if (step != null)
            {
                step.Dispose();
            }
        }
#endif
        }