Пример #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);
     }
 }
Пример #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);
     }
 }
Пример #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);
     }
 }
Пример #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);
     }
 }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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));
 }
Пример #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));
 }