public object Get(string key) { lock (Lock(key)) { return(_memoryCache.Get(key)); } }
/// <summary> /// Gets the value with specified partition and key. If it is a "sliding" or "static" /// value, its lifetime will be increased by the corresponding interval. /// </summary> /// <typeparam name="TVal">The type of the expected value.</typeparam> /// <param name="partition">The partition.</param> /// <param name="key">The key.</param> /// <returns>The value with specified partition and key.</returns> protected override CacheResult <TVal> GetInternal <TVal>(string partition, string key) { var maybeCacheKey = SerializeCacheKey(partition, key); var maybeCacheValue = _store.Get(maybeCacheKey) as CacheValue; return(DeserializeCacheValue <TVal>(maybeCacheValue, partition, key)); }
/// <summary> /// 判断缓存是否已存在 /// </summary> /// <param name="key"></param> /// <returns></returns> public bool Exist(string key) { #if netstandard2_0 Cache.TryGetValue(key, out object value); return(value != null); #endif #if net40 return(Cache.Get(key) != null); #endif }
public object GetValue(string key) { var creator = this.Creator; if (creator == null || this.Exists(key)) { return(_innerCache.Get(key)); } return(this.GetValue(key, _ => { TimeSpan duration; var value = creator.Create(this.Name, _, out duration); return new Tuple <object, TimeSpan>(value, duration); })); }
public override byte[] Get(string key) { #if !(NETCORE || CORE) object obj = _memoryCache.Get(key); if (obj != null) { return((byte[])obj); } else { return(null); } #else object obj; bool success = _memoryCache.TryGetValue(key, out obj); if (success && obj != null) { return((byte[])obj); } else { return(null); } #endif }
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); }
CacheItem <T> ICache.Get <T>(string key) { var value = _cache.Get(key); return(value != null ? (CacheItem <T>)value : null); }
public object Get(string key) { if (key == null) { throw new ArgumentNullException("key"); } return(_cache.Get(key)); }
CacheItem <T> ICache.Get <T>(string key) { var value = _cache.Get(key); if (value != null) { return((CacheItem <T>)value); } else { return(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 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 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; } }
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; } }
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); }
private T GetMemory <T>(string key) where T : class { return(_memorycache.Get(key) as T); }
public object GetValue(string key) { return(_innerCache.Get(key)); }
/// <inheritdoc /> public T Get <T>(string key) { return(cache.Get(key) is T entry ? entry : throw new CacheKeyNotFoundException()); }
public static object CachedenOku(string key) => _cache.Get(key);
public static Schema Get(string key) { var cachedResults = _memCache.Get(key) as Schema; return(cachedResults); }
/// <summary> /// 获取缓存 /// </summary> /// <typeparam name="T">缓存数据类型</typeparam> /// <param name="key">缓存键值</param> /// <returns>检索到的缓存项,未找到该键时为 null。</returns> public T Get <T>(string key) where T : class { var cache = _cache.Get(key); return(cache == null ? null : (T)cache); }
/// <inheritdoc /> public T Get <T>(string key) { return((T)_memoryCache.Get(key)); }
public T Get <T>(string key) { return((T)_cache.Get(key)); }
public T Get(string key) { return((T)cache.Get(key)); }
public T Get <T>(string key) { System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key)); return((T)_cache.Get(key)); }
public object this[string key] { get { return(_cache.Get(key)); } set { _cache.Set(key, value, DateTimeOffset.Now.AddYears(1)); } }
/// <summary> /// 获取缓存 /// </summary> /// <param name="key">缓存键值</param> /// <returns>检索到的缓存项,未找到该键时为 null。</returns> public object Get(string key) { var cache = _cache.Get(key); return(cache); }