protected internal override StoredValue GetCacheItemCore(string region, string key) { EnsureDbCreated(); try { this._locker.EnterReadLock(); object value = null; object memoto = null; this.Db_Read(key, region, out value, out memoto); if (value != null) { var result = new StoredValue(); result.Value = value; if (memoto != null) { //把Memoto转换为原始的Checker var checkerMemoto = memoto as CheckerMemoto; result.Checker = checkerMemoto.Restore(); } return(result); } } catch { } finally { this._locker.ExitReadLock(); } return(null); }
protected override bool AddCore(string region, string key, StoredValue value) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException($"parameter {nameof(key)} can not be null or empty."); } var items = this.GetItems(); if (items == null) { return(false); } if (value == null) { return(false); } #if NET45 if (items.Contains(key)) #endif #if NS2 if (items.ContainsKey(key)) #endif { items[key] = value; } else { items.Add(key, value); } return(true); }
protected internal override bool AddCore(string region, string key, StoredValue value) { EnsureDbCreated(); try { this._locker.EnterWriteLock(); object checkerMemoto = null; if (value.Checker != null) { //真实存储在数据库中的值,是Checker的Memoto checkerMemoto = value.Checker.GetMemoto(); } this.Db_Add(region, key, value.Value, checkerMemoto); return true; } catch { return false; } finally { this._locker.ExitWriteLock(); } }
protected internal override bool AddCore(string region, string key, StoredValue value) { EnsureDbCreated(); try { this._locker.EnterWriteLock(); object checkerMemoto = null; if (value.Checker != null) { //真实存储在数据库中的值,是Checker的Memoto checkerMemoto = value.Checker.GetMemoto(); } this.Db_Add(region, key, value.Value, checkerMemoto); return(true); } catch { return(false); } finally { this._locker.ExitWriteLock(); } }
protected internal override bool AddCore(string region, string key, StoredValue value) { //由于优先使用内存中的缓存,所以添加到硬盘缓存的操作可以异步执行。 AsyncHelper.InvokeSafe(() => { this._disk.AddCore(region, key, value); }); return this._memory.AddCore(region, key, value); }
internal protected override bool AddCore(string region, string key, StoredValue value) { //由于优先使用内存中的缓存,所以添加到硬盘缓存的操作可以异步执行。 AsyncHelper.InvokeSafe(() => { this._disk.AddCore(region, key, value); }); return(this._memory.AddCore(region, key, value)); }
protected internal override bool AddCore(string region, string key, StoredValue value) { return(this._regionCache.Add(key, value, new CacheItemPolicy(), region)); }
internal protected abstract bool AddCore(string region, string key, StoredValue value);
protected internal override StoredValue GetCacheItemCore(string region, string key) { EnsureDbCreated(); try { this._locker.EnterReadLock(); object value = null; object memoto = null; this.Db_Read(key, region, out value, out memoto); if (value != null) { var result = new StoredValue(); result.Value = value; if (memoto != null) { //把Memoto转换为原始的Checker var checkerMemoto = memoto as CheckerMemoto; result.Checker = checkerMemoto.Restore(); } return result; } } catch { } finally { this._locker.ExitReadLock(); } return null; }
protected internal override bool AddCore(string region, string key, StoredValue value) { return this._regionCache.Add(key, value, new CacheItemPolicy(), region); }
protected internal abstract bool AddCore(string region, string key, StoredValue value);