Esempio n. 1
0
 /// <summary>
 ///     Sets the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 public void SetPublic <T>(string key, T value)
 {
     key = MemoryCacheExtensions.PublicCacheKey(key);
     if (!key.IsNullOrEmpty())
     {
         Context.OfMemory().MemoryCache.Set(key, value);
     }
 }
Esempio n. 2
0
 /// <summary>
 ///     Sets the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 public void Set(string key, object value)
 {
     key = MemoryCacheExtensions.TenantCacheKey(key);
     if (!key.IsNullOrEmpty())
     {
         Context.OfMemory().MemoryCache.Set(key, value);
         AddCacheKey(key);
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Removes the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 public void Remove(string key)
 {
     key = MemoryCacheExtensions.TenantCacheKey(key);
     if (!key.IsNullOrEmpty())
     {
         Context.OfMemory().MemoryCache.Remove(key);
         RemoveCacheKey(key);
     }
 }
Esempio n. 4
0
 /// <summary>
 ///     Sets the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="expire">The expire.</param>
 public void Set <T>(string key, T value, TimeSpan expire)
 {
     key = MemoryCacheExtensions.TenantCacheKey(key);
     if (!key.IsNullOrEmpty())
     {
         Context.OfMemory().MemoryCache.Set(key, value, expire);
         AddCacheKey(key);
     }
 }
Esempio n. 5
0
        /// <summary>
        ///     Removes the cache key.
        /// </summary>
        /// <param name="key">The key.</param>
        private void RemoveCacheKey(string key)
        {
            key = MemoryCacheExtensions.TenantCacheKey(key);
            TryGet(AllMemoryObjectCacheKey, out List <string> cacheList);
            if (cacheList == null)
            {
                cacheList = new List <string>();
            }

            if (cacheList.Contains(key))
            {
                cacheList.Remove(key);
                Set(AllMemoryObjectCacheKey, cacheList);
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Get or set of global cache
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataRetriever"></param>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        public CacheValue <T> GetOrSetPublic <T>(Func <T> dataRetriever, string cacheKey) where T : class
        {
            cacheKey = MemoryCacheExtensions.PublicCacheKey(cacheKey);
            TryGetPublic(cacheKey, out T result);
            if (result != null)
            {
                return(new CacheValue <T>(result, true));
            }

            var item = dataRetriever?.Invoke();

            if (item != null)
            {
                SetPublic(cacheKey, item);
                return(new CacheValue <T>(item, true));
            }

            return(CacheValue <T> .NoValue);
        }
Esempio n. 7
0
 /// <summary>
 ///     Gets the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 public T Get <T>(string key)
 {
     key = MemoryCacheExtensions.TenantCacheKey(key);
     return(Context.OfMemory().MemoryCache.Get <T>(key));
 }
Esempio n. 8
0
 /// <summary>
 ///     Try get of global cache
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool TryGetPublic <T>(string key, out T value)
 {
     key = MemoryCacheExtensions.PublicCacheKey(key);
     return(Context.OfMemory().MemoryCache.TryGetValue(key, out value));
 }