public byte[] GetTemporaryFile(string fileKey) { if (cacheManager.IsExists(fileKey)) { byte[] file = cacheManager.Get(fileKey) as byte[]; cacheManager.Remove(fileKey); return(file); } else { return(new List <byte>().ToArray()); } }
public void Can_remove_by_key() { _cacheManager.Set("some_key_1", 1); _cacheManager.IsSet("some_key_1").Should().BeTrue(); _cacheManager.Remove("some_key_1"); _cacheManager.IsSet("some_key_1").Should().BeFalse(); }
public ResponseDto <String> Logout() { MemoryCacheManager.Remove(this.Token); return(new ResponseDto <string>() { Code = CommonEnum.ToLoginCode }); }
public void Intercept(IInvocation invocation) { if (AllowAnonymous(invocation.MethodInvocationTarget, invocation.TargetType)) { var clientInfo = ClientInfoProvider.GetClientInfo(); var key = invocation.Method.Name + invocation.Method.ReflectedType.Name + clientInfo.ClientIpAddress + clientInfo.ComputerName; var keycache = _cacheManager.GetCache(key); if (keycache == null) { //3秒内不能重复提交 _cacheManager.SetCache(key, DateTime.Now, 3); invocation.Proceed(); if (invocation.Method.IsAsync()) { if (invocation.Method.ReturnType == typeof(Task)) { invocation.ReturnValue = AsyncHelper.AwaitTaskWithFinally( (Task)invocation.ReturnValue, exception => _cacheManager.Remove(key) ); } else { invocation.ReturnValue = AsyncHelper.CallAwaitTaskWithFinallyAndGetResult( invocation.Method.ReturnType.GenericTypeArguments[0], invocation.ReturnValue, exception => _cacheManager.Remove(key) ); } } else { _cacheManager.Remove(key); } } else { throw new Exception("请不要重复提交!"); } } else { invocation.Proceed(); } }
public void PassesMemoryCacheManager_Set_Success() { _cacheManager.Set("name", "joe", int.MaxValue); _cacheManager.HasKey("name").TestBeTrue(); _cacheManager.Get <string>("name").TestEqual("joe"); _cacheManager.Remove("name"); _cacheManager.HasKey("name").TestBeFalse(); }
public void MemoryCacheManager_Should_Not_Throw_Exception_When_Trying_To_Remove_A_Non_Excisting_Key() { ICacheManager cacheManager = new MemoryCacheManager(); cacheManager.Remove("Test"); Assert.IsFalse(cacheManager.Contains("Test")); }
public void RemoveTest(string key, string region) { _manager.Set(key, new object(), region: region); Assert.NotNull(_manager.Get(key, region)); _manager.Remove(key, region); Assert.Null(_manager.Get(key, region)); }
public void removing_one_item_of_Cache() { MemoryCacheManager memoryCacheManager = new MemoryCacheManager(); memoryCacheManager.Set("exampleKey15", 5, int.MaxValue); Assert.IsTrue(memoryCacheManager.IsSet("exampleKey15")); memoryCacheManager.Remove("exampleKey15"); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey15")); }
public void RemoveExample1() { ICacheManager cacheManager = new MemoryCacheManager(); string inputString = Console.ReadLine(); const string cacheKey = "MyKey"; const double saveHours = 1; cacheManager.SetByAbsolute(cacheKey, inputString, saveHours); cacheManager.Remove(cacheKey); }
public void MemoryCacheManager_Should_Return_Null_When_Item_From_Cache_Was_Removed_And_Afterwards_Requested() { ICacheManager cacheManager = new MemoryCacheManager(); cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy()); cacheManager.Remove("Test"); Assert.IsFalse(cacheManager.Contains("Test")); }
public void MemoryCacheManager测试() { string key = "Memory_TEST_KEY"; string memoryValue = "Memory测试"; ICacheManager cache = new MemoryCacheManager(); cache.Set(key, memoryValue, 60); string value= cache.Get<string>(key); Assert.AreEqual(value, memoryValue); cache.Remove(key); }
public async Task Removing_one_item_of_Cache() { MemoryCacheManager memoryCacheManager = new MemoryCacheManager(new MemoryCache(new MemoryCacheOptions { })); await memoryCacheManager.Set("exampleKey15", 5, int.MaxValue); Assert.IsTrue(memoryCacheManager.IsSet("exampleKey15")); await memoryCacheManager.Remove("exampleKey15"); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey15")); }
public void MemoryCacheManager测试() { string key = "Memory_TEST_KEY"; string memoryValue = "Memory测试"; ICacheManager cache = new MemoryCacheManager(); cache.Set(key, memoryValue, 60); string value = cache.Get <string>(key); Assert.AreEqual(value, memoryValue); cache.Remove(key); }
public ActionResult ClearCacheItem(string key) { if (string.IsNullOrEmpty(key)) { var cacheManager = new MemoryCacheManager(); cacheManager.Clear(); } else { var cacheManager = new MemoryCacheManager(); cacheManager.Remove(key); } return(RedirectToAction("Index", "Home")); }
/// <summary> /// 根据用户UID初始化用户权限对象并设置全局缓存 /// </summary> /// <param name="uid"></param> private static void SettingLimits(string uid) { var ukey = uid + "_" + key_limitId; //取权限 var roleBLL = new SysRoleBLL(); var objs = roleBLL.GetRoleLimitsByUId(uid); //设置缓存 var cacheManager = new MemoryCacheManager(); if (cacheManager.IsSet(ukey)) { cacheManager.Remove(ukey); } cacheManager.Set(ukey, objs, 1440); }
public IActionResult GetAll() { var list = _userService.GetAll(); if (list != null) { var cm = new MemoryCacheManager(); string cacheKey = "users"; if (cm.Contains(cacheKey)) { cm.Remove(cacheKey); } cm.Add(cacheKey, list); return(Ok(list)); } return(BadRequest()); }
public void MemoryCacheManager_Should_Contain_Only_Values_That_Where_Not_To_Be_Deleted() { ICacheManager cacheManager = new MemoryCacheManager(); cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy()); cacheManager.Add("Test2", "Dit is de tweede waarde...", new CacheItemPolicy()); cacheManager.Add("Test3", "Dit is de derde waarde...", new CacheItemPolicy()); IList <string> collection = new List <string> { "Test", "Test3" }; cacheManager.Remove(collection); Assert.AreEqual(1, cacheManager.Count()); }
private void RemoveWidgetZoneFromCache(string widgetZoneName) { var cacheManager = new MemoryCacheManager(); var cacheKey = string.Format(ModelCacheEventConsumer.WIDGET_MODEL_KEY, _storeContext.CurrentStore.Id, widgetZoneName); cacheManager.Remove(cacheKey); }