protected virtual bool GetCacheInstance(string key, ICacheDataConverter converter, out object value) { value = null; var byteData = Cache.Get(key); if (byteData == null) { return(false); } DistributeData data = DistributeData.FromDistributeData(byteData); if (!data.Dependency.HasChanged) { value = data.CreateCacheObject(converter); return(true); } else { Cache.Remove(key); } value = null; return(false); }
internal override void SetCacheData(string key, DistributeData data, DistributedCacheEntryOptions options) { fLock.WriteLockAction(() => { fCacheTable.TryAdd(key, new WeakReference <DistributeData>(data)); Cache.Set(key, data.ToDistributeData(), options); return(true); }); }
public static DistributeData FromDistributeData(byte[] data) { string json = Encoding.UTF8.GetString(data); DistributeData result = new DistributeData(); result.ReadJson(json); result.CreateDependency(); return(result); }
private void AddCacheInstance(string key, object instance, ICacheDataConverter converter, IDistributeCacheDependency dependency, bool useCache) { bool canCache = useCache || (BaseAppSetting.Current != null && BaseAppSetting.Current.UseCache); if (canCache) { DistributeData data = new DistributeData(converter, instance, dependency); var expiration = dependency.GetAbsoluteExpiration(); DateTimeOffset absolute = expiration ?? new DateTimeOffset(DateTime.Today.AddDays(1)); DistributedCacheEntryOptions options = new DistributedCacheEntryOptions { AbsoluteExpiration = absolute }; SetCacheData(key, data, options); } }
protected override bool GetCacheInstance(string key, ICacheDataConverter converter, out object value) { value = null; DistributeData data; if (fCacheTable.TryGetValue(key, out var localCache)) { if (localCache.TryGetTarget(out data)) { if (!data.Dependency.HasChanged) { value = data.CreateCacheObject(converter); return(true); } else { Remove(key); return(false); } } } var byteData = Cache.Get(key); if (byteData == null) { return(false); } data = DistributeData.FromDistributeData(byteData); if (!data.Dependency.HasChanged) { value = data.CreateCacheObject(converter); fCacheTable[key] = new WeakReference <DistributeData>(data); return(true); } else { Remove(key); } value = null; return(false); }
internal virtual void SetCacheData(string key, DistributeData data, DistributedCacheEntryOptions options) { Cache.Set(key, data.ToDistributeData(), options); }