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()); }
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); }
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); }
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); }
public async Task SetValueAsync <T2>(NoSQLKey key, T2 value) { string jsonData = JsonConvert.SerializeObject(value); await _database.StringSetAsync(key.Key, jsonData, key.CacheTime); }
public void SetValue <T2>(NoSQLKey key, T2 value) { string jsonData = JsonConvert.SerializeObject(value); _database.StringSet(key.Key, jsonData, key.CacheTime); }
public Task <bool> IsKeyExistAsync(NoSQLKey key) => _database.KeyExistsAsync(key.Key);
public bool IsKeyExist(NoSQLKey key) => _database.KeyExists(key.Key);
public Task <bool> RemoveKeyAsync(NoSQLKey key) => _database.KeyDeleteAsync(key.Key);
public bool RemoveKey(NoSQLKey key) => _database.KeyDelete(key.Key);