Exemple #1
0
        /// <summary>
        /// Retrieves a value from storage
        /// </summary>
        /// <typeparam name="T">the type of value</typeparam>
        /// <param name="key">the key to retrieve</param>
        /// <param name="valueLoader">delegate to populate the value if it does not exist in storage</param>
        /// <param name="expires">when this object expires</param>
        /// <returns>the value</returns>
        public T Retrieve <T>(string key, DateTime?expires, StoredValueLoader valueLoader)
        {
            object oValue = Cache.Get(CACHE_TYPE, GetCacheKey(key));

            if (oValue == null && valueLoader != null)
            {
                oValue = valueLoader();

                if (oValue != null)
                {
                    Save(key, oValue, expires);
                }
            }

            return(oValue == null ? default(T) : (T)oValue);
        }
Exemple #2
0
        /// <summary>
        /// Retrieves a value from storage
        /// </summary>
        /// <typeparam name="T">the type of value</typeparam>
        /// <param name="key">the key to retrieve</param>
        /// <param name="valueLoader">delegate to populate the value if it does not exist in storage</param>
        /// <param name="expires">the sliding expiration for this object in seconds</param>
        /// <returns>the value</returns>
        internal T Retrieve <T>(string key, int expires, StoredValueLoader valueLoader)
        {
            object oValue = Cache.Get(CACHE_TYPE, GetCacheKey(key));

            if (oValue == null && valueLoader != null)
            {
                oValue = valueLoader();

                if (oValue != null)
                {
                    Save(key, oValue, DateTime.Now.AddSeconds(expires));
                }
            }

            return(oValue == null ? default(T) : (T)oValue);
        }
Exemple #3
0
 /// <summary>
 /// Retrieves a value from storage
 /// </summary>
 /// <typeparam name="T">the type of value</typeparam>
 /// <param name="key">the key to retrieve</param>
 /// <param name="valueLoader">delegate to populate the value if it does not exist in storage</param>
 /// <returns>the value</returns>
 public T Retrieve <T>(string key, StoredValueLoader valueLoader)
 {
     return(Retrieve <T>(key, null, valueLoader));
 }