Esempio n. 1
0
        public IActionResult Index()
        {
            TTLExtendableCacheObject <DateTime> saat()
            {
                return(new TTLExtendableCacheObject <DateTime>(DateTime.Now, DateTime.Now));
            }

            var cacheKey = _cacheManager.PrepareKeyForDefaultCache(AdminDefaults.RoleByIDCacheKey, 1);

            cacheKey.CacheTime = TimeSpan.FromHours(1);

            var cacheRefreshKey = _cacheManager.PrepareKeyForDefaultCache(AdminDefaults.RefreshRoleByIDCacheKey, 1);

            cacheRefreshKey.CacheTime = TimeSpan.FromSeconds(10);

            DateTime LastUpdateDate() =>
            DateTime.Now;

            TTLExtendableCacheObject <DateTime> dt = _cacheManager.GetOrCreate(cacheKey,
                                                                               saat, cacheRefreshKey, LastUpdateDate);

            ViewBag.dt = dt.CacheObject;


            NoSQLKey CategoriesByLangCacheKey = new NoSQLKey("Redis.CategoriesByLang-{0}");

            return(View());
        }
Esempio n. 2
0
        public async Task <T2> GetOrCreateAsync <T2>(NoSQLKey key, Func <Task <T2> > acquire)
        {
            RedisValue resultExist = await _database.StringGetAsync(key.Key);

            if (resultExist.HasValue)
            {
                return(JsonConvert.DeserializeObject <T2>(resultExist));
            }

            var result = await acquire();

            if (key.CacheTime.TotalMinutes > 0)
            {
                await SetValueAsync(key, result);
            }

            return(result);
        }
Esempio n. 3
0
        public T2 GetOrCreate <T2>(NoSQLKey key, Func <T2> acquire)
        {
            RedisValue resultExist = _database.StringGet(key.Key);

            if (resultExist.HasValue)
            {
                return(JsonConvert.DeserializeObject <T2>(resultExist));
            }

            var result = acquire();

            if (key.CacheTime.TotalMinutes > 0)
            {
                SetValue(key, result);
            }

            return(result);
        }
Esempio n. 4
0
        public TTLExtendableCacheObject <T2> GetOrCreate <T2>(NoSQLKey key, Func <TTLExtendableCacheObject <T2> > acquire, NoSQLKey refreshKey, Func <DateTime> ladAcquire)
        {
            var result = GetOrCreate(key, acquire);

            Task.Run(() =>
            {
                if (!IsKeyExist(refreshKey))
                {
                    var lad = ladAcquire();

                    if (refreshKey.CacheTime.TotalMinutes > 0)
                    {
                        SetValue(refreshKey, lad);
                    }

                    if (lad == result.LastUpdateDate)
                    {
                        _database.KeyExpire(key.Key, key.CacheTime);
                    }
                }
            });

            return(result);
        }
Esempio n. 5
0
 public async Task SetValueAsync <T2>(NoSQLKey key, T2 value)
 {
     string jsonData = JsonConvert.SerializeObject(value);
     await _database.StringSetAsync(key.Key, jsonData, key.CacheTime);
 }
Esempio n. 6
0
        public void SetValue <T2>(NoSQLKey key, T2 value)
        {
            string jsonData = JsonConvert.SerializeObject(value);

            _database.StringSet(key.Key, jsonData, key.CacheTime);
        }
Esempio n. 7
0
 public Task <bool> IsKeyExistAsync(NoSQLKey key) => _database.KeyExistsAsync(key.Key);
Esempio n. 8
0
 public bool IsKeyExist(NoSQLKey key) => _database.KeyExists(key.Key);
Esempio n. 9
0
 public Task <bool> RemoveKeyAsync(NoSQLKey key) => _database.KeyDeleteAsync(key.Key);
Esempio n. 10
0
 public bool RemoveKey(NoSQLKey key) => _database.KeyDelete(key.Key);