public bool Rename(string key, string newKey) { if (string.IsNullOrWhiteSpace(newKey)) { throw new ArgumentNullException("newKey"); } #if !CORE_CLR var orignalValue = _innerCache.Remove(key); if (orignalValue != null) { _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration); } return(orignalValue != null); #else object orignalValue; if (_innerCache.TryGetValue(key, out orignalValue)) { _innerCache.Remove(key); _innerCache.Set(newKey, orignalValue, new MemoryCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.MaxValue }); } return(orignalValue != null); #endif }
public static void CacheEkle(string key, object value, int expireAsMinute) { if (_cache.Any(x => x.Key == key)) { _cache.Remove(key); } _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute)); }
static void Main() { KeyValuePairs.Add(new System.Runtime.Caching.CacheItem("key1", "value1"), new System.Runtime.Caching.CacheItemPolicy()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); BonusSkins.Register(); SkinManager.EnableFormSkins(); Application.Run(new MainForm()); }
private void WriteToCache(String userAgent, DeviceInfo device) { var uaHash = HashUserAgentString(userAgent); var _cachePolicy = new System.Runtime.Caching.CacheItemPolicy() { AbsoluteExpiration = new DateTimeOffset( DateTime.UtcNow.AddSeconds(_durationInSeconds)) }; _cache.Add(uaHash, device, _cachePolicy); }
public void Set(string key, object value, int expiresAsMinute) { System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key)); System.Diagnostics.Contracts.Contract.Assert(value != null); System.Diagnostics.Contracts.Contract.Assert(expiresAsMinute > 0); if (IsExist(key)) { Remove(key); } _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expiresAsMinute)); }
public void Set(string key, object value, int expireAsMinute) { //tek islemde Exeption firlatmak //icine verilen kosul dogru ise OK degilse exeption fırlatir //Contract namespace altındaki assertion ları kullandık System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key)); System.Diagnostics.Contracts.Contract.Assert(value != null); System.Diagnostics.Contracts.Contract.Assert(expireAsMinute > 0); if (IsExist(key)) { Remove(key); } _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute)); }
public T GetIniValue <T>(string initKey, string defaultValue = "", bool allowEmptyValue = true, bool rewriteOnBadCast = true, Boolean cached = true) { T retValue; if (cached) { if (m_SettingsCache.Contains(m_InitGroup + "|" + initKey)) { retValue = (T)m_SettingsCache.Get(m_InitGroup + "|" + initKey); } else { retValue = m_DBCon.getIniValue <T>(m_InitGroup, initKey, defaultValue, allowEmptyValue, rewriteOnBadCast); m_SettingsCache.Add(m_InitGroup + "|" + initKey, retValue, DateTime.UtcNow + new TimeSpan(0, 0, 1, 0)); } } else { retValue = m_DBCon.getIniValue <T>(m_InitGroup, initKey, defaultValue, allowEmptyValue, rewriteOnBadCast); m_SettingsCache.Add(m_InitGroup + "|" + initKey, retValue, DateTime.UtcNow + new TimeSpan(0, 0, 1, 0)); } return(retValue); }
public bool Rename(string key, string newKey) { if (string.IsNullOrWhiteSpace(newKey)) { throw new ArgumentNullException("newKey"); } var orignalValue = _innerCache.Remove(key); if (orignalValue != null) { _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration); } return(orignalValue != null); }
public AppCache() { System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; List <AppModel> _cacheapps = mcache.Get(getcachename) as List <AppModel>; if (_cacheapps == null) { _cacheapps = new List <AppModel>(); bool r = mcache.Add(getcachename, _cacheapps, new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { throw new Exception("初始化缓存失败。"); } } cacheapps = _cacheapps.CloneList(); }
public void TestRunTimeCache() { var cache = new System.Runtime.Caching.MemoryCache("sys"); cache.Add("user", new User { Name = "Foo" }, DateTime.Now.AddDays(1)); User f = (User)cache.Get("user"); Assert.Equal("Foo", f.Name); f.Name = "Bar"; var b = (User)cache.Get("user"); Assert.Equal("Bar", b.Name); }
public CertCache(ServiceCertType certtype) { this.certtype = certtype; System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; List <CertCacheItem> _tempmanagecache = mcache.Get(cachetypename) as List <CertCacheItem>; if (_tempmanagecache == null) { _tempmanagecache = new List <CertCacheItem>(); bool r = mcache.Add(cachetypename, _tempmanagecache, new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { throw new Exception("初始化缓存失败。"); } } tempmanagecache = _tempmanagecache.CloneList(); }
private void SetCertCahe() { System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; if (tempmanagecache == null) { tempmanagecache = new List <CertCacheItem>(); } if (mcache.Get(cachetypename) != null) { mcache.Remove(cachetypename); } bool r = mcache.Add(cachetypename, tempmanagecache.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { mcache = null; } }
private void SetCache() { System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; if (cacheapps == null) { cacheapps = new List <AppModel>(); } if (mcache.Get(getcachename) != null) { mcache.Remove(getcachename); } bool r = mcache.Add(getcachename, cacheapps.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { mcache = null; } }
/// <inheritdoc /> public bool Add(string key, object value) { return(_memoryCache.Add(key, value, DateTimeOffset.MaxValue)); }
public static void Set(string key, object o, int timeout) { System.Runtime.Caching.MemoryCache cache = System.Runtime.Caching.MemoryCache.Default; cache.Add(TransformKey(key), o, DateTime.Now.AddMinutes(timeout)); }