Esempio n. 1
0
        /// <summary>
        /// Cach data from two days..
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="key"></param>
        public static void AddCache <T>(T item, string key)
        {
            //Create Cache Configuration Item using the key..
            CacheItemConfig cacheItemConfig = new CacheItemConfig(new CacheKey(key), new TimeSpan(2, 0, 0, 0));

            CacheManager.Add(cacheItemConfig, item);
        }
Esempio n. 2
0
        /// <summary>
        /// <see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/>
        /// </summary>
        /// <typeparam name="TResult"><see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/></typeparam>
        /// <param name="cacheItemConfig"><see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/></param>
        /// <param name="result"><see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/>></param>
        /// <returns><see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/></returns>
        public bool Get <TResult>(CacheItemConfig cacheItemConfig, out TResult result)
        {
            if (cacheItemConfig != null)
            {
                string cacheKey = cacheItemConfig.CacheKey.GetCacheKey();

                //get object from cache and check if exists
                object cachedItem = this.m_CacheFactory.Get(cacheKey);

                if (cachedItem != null)
                {
                    result = (TResult)cachedItem;

                    return(true);
                }
                else
                {
                    result = default(TResult);

                    return(false);
                }
            }
            else
            {
                throw new ArgumentNullException("cacheItem");
            }
        }
Esempio n. 3
0
        public static T GetCache <T>(string key)
        {
            //Create Cache Configuration Item using the key..
            CacheItemConfig cacheItemConfig = new CacheItemConfig(new CacheKey(key));

            //Get Cached Data...
            T cachedData;

            CacheManager.Get <T>(cacheItemConfig, out cachedData);
            return(cachedData);
        }
Esempio n. 4
0
 /// <summary>
 /// <see cref="M:Kashef.Common.Utilities.Cache..Get{TResult}"/>
 /// </summary>
 /// <param name="cacheItemConfig"><see cref="M:Kashef.Common.Utilities.Cache.Caching.Get{TResult}"/></param>
 /// <param name="value"><see cref="M:Kashef.Common.Utilities.Cache.Get{TResult}"/></param>
 public void Add(CacheItemConfig cacheItemConfig, object value)
 {
     if (value != null && cacheItemConfig != null)
     {
         string   cachekey       = cacheItemConfig.CacheKey.GetCacheKey();
         TimeSpan expirationTime = cacheItemConfig.ExpirationTime;
         this.m_CacheFactory.Add(cachekey, value, new DateTimeOffset(DateTime.Now.AddTicks(expirationTime.Ticks)));
     }
     else if (cacheItemConfig == null)
     {
         throw new ArgumentNullException(Properties.Resources.Exception_CacheItemKeyNull);
     }
 }