public void Add(ICacheKey cacheKey, object value, ICacheDependency dependency, DateTime expirationDate, TimeSpan slidingSpan, RuntimeCommon.Caching.CacheItemPriority priority) { var policy = new CacheItemPolicy(); { //configurations var depKeys = TransformDependency(dependency)?.ToList(); if (!depKeys.IsNullOrEmpty()) { foreach (var key in depKeys) { subscription.SubscribeTopic(key); } var monitor = new PubSubMonitor(cacheKey.GetKeyAsString(), depKeys, filter); policy.ChangeMonitors.Add(monitor); } policy.SlidingExpiration = slidingSpan == CacheUtils.NoSliding ? ObjectCache.NoSlidingExpiration : slidingSpan; policy.AbsoluteExpiration = expirationDate == CacheUtils.NoExpiration ? ObjectCache.InfiniteAbsoluteExpiration : expirationDate; policy.Priority = priority == RuntimeCommon.Caching.CacheItemPriority.NotRemovable ? System.Runtime.Caching.CacheItemPriority.NotRemovable : System.Runtime.Caching.CacheItemPriority.Default; } memoryCacheInstance.Set(cacheKey.GetKeyAsString(), value, policy); }
public void AddObject(string objectId, object o, ICacheDependency dep) { lock (lockHelper) { cachedStrategy.AddObjectWithDepend(objectId, o, dep); } }
protected override bool Add(string regName, BasePlugInAttribute attribute, Type type) { Attribute instanceAttr = Attribute.GetCustomAttribute(type, typeof(InstancePlugInAttribute)); if (instanceAttr != null) { BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; FieldInfo fieldInfo = type.GetField("Instance", flags); if (fieldInfo == null) { fieldInfo = type.GetField("INSTANCE", flags); if (fieldInfo == null) { return(false); } } object value = ObjectUtil.GetStaticValue(fieldInfo); if (value == null) { return(false); } ICacheDependency dependency = CacheUtil.GetDependency(type, null); if (dependency == null) { dependency = AlwaysDependency.Dependency; } return(AddInstance(regName, attribute, value, dependency) != null); } else { return(base.Add(regName, attribute, type)); } }
public CacheTokenItem(string type, string[] tokens, ICacheDependency cacheDependency, string varyHeader) { TypeName = type; _tokens = tokens; VaryHeader = varyHeader; }
public SqlCodeTable(MarcoConfigItem sql) { TkDebug.AssertArgumentNull(sql, "sql", null); Sql = sql; fDependency = NoDependency.Dependency; }
public object GetItem(string key, BaseCacheItemCreator creator, params object[] args) { object result = null; ICacheDataConverter converter = GetDataConverter(creator); var distributeKey = GetDistributeKey(creator, key); if (GetCacheInstance(distributeKey, converter, out var cacheObject)) { return(cacheObject); } try { result = creator.Create(key, args); TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者没有创建缓存对象,请确认", creator.GetType()), creator); } catch (Exception ex) { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者在创建对象时发生例外,请检查原因", creator.GetType()), ex, creator); } ICacheDependency dependency = CacheUtil.SearchDependency(result); IDistributeCacheDependency distributeDependency = dependency as IDistributeCacheDependency; TkDebug.AssertNotNull(distributeDependency, $"附着的ICacheDependency(类型为{dependency.GetType()})不支持IDistributeCacheDependency", dependency); AddCacheInstance(distributeKey, result, converter, distributeDependency, creator.Attribute.ForceCache); return(result); }
private static CacheItemPolicy BuildCachePolicy( DateTime?absoluteExpiration = null, TimeSpan?slidingExpiration = null, CacheEntryRemovedCallback removed = null, CacheEntryUpdateCallback updated = null, ICacheDependency dependency = null) { var policy = new CacheItemPolicy { Priority = CacheItemPriority.Default, AbsoluteExpiration = absoluteExpiration.HasValue ? absoluteExpiration.Value : ObjectCache.InfiniteAbsoluteExpiration, SlidingExpiration = slidingExpiration.HasValue ? slidingExpiration.Value : ObjectCache.NoSlidingExpiration, RemovedCallback = removed, UpdateCallback = updated }; if (dependency != null) { var fileDependency = dependency as IFileCacheDependency; if (fileDependency != null) { policy.ChangeMonitors.Add(new HostFileChangeMonitor(fileDependency.FilePaths)); } } return(policy); }
/// <summary> /// 添加指定ID的cache 有依赖项 /// </summary> /// <param name="objId"></param> /// <param name="o"></param> /// <param name="dep">ICacheDependency</param> public void AddObjectWithDepend(string objId, object o, ICacheDependency dep) { if (dep.DependType == EnumDependType.CacheDepend) { string depend_key = CacheKey.DEPEND + objId; string depend_value = dep.Dependkey; string depctime_key = CacheKey.DEPCTIME + objId; object depctime_value = GetCache(CacheKey.CTIME + dep.Dependkey); //判断dependkey是否存在 if (depctime_value != null) { AddObject(objId, o); //Depend key AddCache(depend_key, depend_value); //DEPTIME AddCache(depctime_key, depctime_value); } else { AddObject(objId, o); } } else// 文件依赖 { ///TODO: } }
public CacheManager(IServiceProvider provider) { _distributedCache = provider.GetRequiredService <IDistributedCache>(); _cacheDependency = provider.GetRequiredService <ICacheDependency>(); _memoryCache = provider.GetRequiredService <IMemoryCache>(); _config = provider.GetRequiredService <IConfiguration>(); _logger = provider.GetRequiredService <ILogger <CacheManager> >(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="key">缓存项健值</param> /// <param name="value">储存项值</param> /// <param name="cacheDependency">过期策略</param> public CacheItem(string key, object @value, ICacheDependency cacheDependency) { this.Key = key; this.Value = @value; this.CacheDependency = cacheDependency; this.Hits = 0; this.LastAccessTime = DateTime.Now; }
public SimpleCacheManager(ICacheDependency cacheDependency, IMemoryCache memoryCache, ILogger <CacheManager> logger) { _cacheDependency = cacheDependency; _memoryCache = memoryCache; _logger = logger; }
/// <summary> /// Initializes a new instance of the InstanceRegItem class. /// </summary> public InstanceRegItem(string regName, BasePlugInAttribute attribute, object instance, ICacheDependency dependency) : base(regName, attribute) { fInstance = instance; fInstanceType = instance.GetType(); Dependency = dependency; }
public CacheItem(object value, ICacheDependency expires) : this(value) { if (expires == null) { throw new ArgumentNullException(nameof(expires)); } this.Dependencies.Add(expires); }
public bool Set <T>(string key, T value, TimeSpan slidingExpiration, ICacheDependency dependency) { return(Try(() => { var entry = CreateEntry(slidingExpiration: slidingExpiration); SetWithType(key, value, entry); })); }
/// <summary> /// Initializes a new instance of the XsltTransformCacheData class. /// </summary> /// <param name="fileNames"></param> public XsltTransformCacheData(XslCompiledTransform transform, string[] fileNames) { fFileNames = fileNames; Transform = transform; //fAttribute = fileNames == null ? AlwaysCacheAttribute.Attribute : // new FilesCacheAttribute(fFileNames, FilePathPosition.AbsolutePath); fDependency = AlwaysDependency.Dependency; }
public bool Set <T>(string key, T value, DateTimeOffset absoluteExpiration, ICacheDependency dependency) { return(Try(() => { var entry = CreateEntry(absoluteExpiration); SetWithType(key, value, entry); })); }
public bool Set <T>(string key, T value, ICacheDependency dependency) { return(Try(() => { var entry = CreateEntry(); SetWithType(key, value, entry); })); }
public static DateTimeOffset?GetAbsoluteExpiration(this ICacheDependency dependency) { if (dependency is ICacheDependencyTime dependencyTime) { return(new DateTimeOffset(dependencyTime.AbsoluteExpiration)); } return(null); }
public bool Add <T>(string key, T value, TimeSpan slidingExpiration, ICacheDependency dependency) { if (Cache.Get(key) != null) { return(false); } Cache.Set(key, value, CreateEntry(slidingExpiration: slidingExpiration)); return(true); }
public bool Add <T>(string key, T value, DateTimeOffset absoluteExpiration, ICacheDependency dependency) { if (Cache.Get(key) != null) { return(false); } Cache.Set(key, value, CreateEntry(absoluteExpiration, dependency: dependency)); return(true); }
public bool Add <T>(string key, T value, ICacheDependency dependency) { if (Cache.Get(key) != null) { return(false); } Cache.Set(key, value, CreateEntry(dependency: dependency)); return(true); }
public void AddCacheDependency(ICacheDependency cacheDependency) { if (_dependencies == null) { _dependencies = new List <ICacheDependency>(); } _dependencies.Add(cacheDependency); }
public bool Add(string key, object value, ICacheDependency dependency) { if (_cache.Get(key) != null) { return(false); } _cache.Set(key, value, CreateEntry(dependency: dependency)); return(true); }
/// <summary> /// Converts abstraction to implementation /// </summary> /// <param name="dependency"></param> /// <returns></returns> protected virtual CacheDependency ConvertDependency(ICacheDependency dependency) { if (dependency == null) { return(null); } return(new CacheDependency(dependency.FileNames?.ToArray(), dependency.CacheKeys?.ToArray(), dependency.SubCacheDependency != null ? ConvertDependency(dependency.SubCacheDependency) : null)); }
public bool Add(string key, object value, DateTime absoluteExpiration, ICacheDependency dependency) { if (_cache.Get(key) != null) { return(false); } _cache.Set(key, value, CreateEntry(absoluteExpiration, dependency: dependency)); return(true); }
/****************************************************************************/ public override void Add(string key, object objToAdd, DateTime expires, ICacheDependency dependency = null) { try { System.Web.Hosting.HostingEnvironment.Cache.Insert(key, objToAdd, ToCacheDependency(dependency), expires, System.Web.Caching.Cache.NoSlidingExpiration); } catch { } }
/****************************************************************************/ public override void Add(string key, object objToAdd, TimeSpan expires, ICacheDependency dependency = null) { try { System.Web.Hosting.HostingEnvironment.Cache.Insert(key, objToAdd, ToCacheDependency(dependency), System.Web.Caching.Cache.NoAbsoluteExpiration, expires); } catch { } }
public bool Add <T>(string key, T value, ICacheDependency dependency) { if (_cache.Get(key) != null) { return(false); } var entry = CreateEntry(); SetWithType(key, value, entry); return(true); }
public bool Add <T>(string key, T value, TimeSpan slidingExpiration, ICacheDependency dependency) { if (_cache.Get(key) != null) { return(false); } var entry = CreateEntry(slidingExpiration: slidingExpiration); SetWithType(key, value, entry); return(true); }
public bool Add <T>(string key, T value, DateTimeOffset absoluteExpiration, ICacheDependency dependency) { if (_cache.Get(key) != null) { return(false); } var entry = CreateEntry(absoluteExpiration); SetWithType(key, value, entry); return(true); }
public IList<Blog> GetAll() { var sqlCacheDependency = cacheProvider.CreateCacheDependency<ISqlCacheDependency>() .Initialise("BloggingContext", "Blogs"); ICacheDependency[] cacheDependencies = new ICacheDependency[] { sqlCacheDependency }; string key = string.Format("CacheDiSample.DataAccess.GetAll"); return cacheProvider.Fetch(key, () => { return parentBlogRepository.GetAll(); }, null, null, cacheDependencies) .ToList(); }
public CacheDetails( TimeSpan absoluteCacheExpiration, TimeSpan slidingCacheExpiration, ICacheDependency cacheDependency ) { if (absoluteCacheExpiration == null) throw new ArgumentNullException("absoluteCacheExpiration"); if (slidingCacheExpiration == null) throw new ArgumentNullException("slidingCacheExpiration"); if (cacheDependency == null) throw new ArgumentNullException("cacheDependency"); this.absoluteCacheExpiration = absoluteCacheExpiration; this.slidingCacheExpiration = slidingCacheExpiration; this.cacheDependency = cacheDependency; }
public SiteMapLoaderContainer(ConfigurationSettings settings) { // Singleton instances if (settings.EnableSiteMapFile) { this.absoluteFileName = HostingEnvironment.MapPath(settings.SiteMapFileName); } this.mvcContextFactory = new MvcContextFactory(); #if NET35 this.siteMapCache = new SiteMapCache(new AspNetCacheProvider<ISiteMap>(this.mvcContextFactory)); #else this.siteMapCache = new SiteMapCache(new RuntimeCacheProvider<ISiteMap>(System.Runtime.Caching.MemoryCache.Default)); #endif this.cacheDependency = this.ResolveCacheDependency(settings); this.requestCache = this.mvcContextFactory.GetRequestCache(); this.bindingFactory = new BindingFactory(); this.bindingProvider = new BindingProvider(this.bindingFactory, this.mvcContextFactory); this.urlPath = new UrlPath(this.mvcContextFactory, this.bindingProvider); this.siteMapCacheKeyGenerator = new SiteMapCacheKeyGenerator(this.mvcContextFactory); this.siteMapCacheKeyToBuilderSetMapper = new SiteMapCacheKeyToBuilderSetMapper(); this.reservedAttributeNameProvider = new ReservedAttributeNameProvider(settings.AttributesToIgnore); var siteMapNodeFactoryContainer = new SiteMapNodeFactoryContainer(settings, this.mvcContextFactory, this.urlPath, this.reservedAttributeNameProvider); this.siteMapNodeToParentRelationFactory = new SiteMapNodeToParentRelationFactory(); this.nodeKeyGenerator = new NodeKeyGenerator(); this.siteMapNodeFactory = siteMapNodeFactoryContainer.ResolveSiteMapNodeFactory(); this.siteMapNodeCreatorFactory = this.ResolveSiteMapNodeCreatorFactory(); this.cultureContextFactory = new CultureContextFactory(); this.dynamicSiteMapNodeBuilderFactory = new DynamicSiteMapNodeBuilderFactory(this.siteMapNodeCreatorFactory, this.cultureContextFactory); this.siteMapHierarchyBuilder = new SiteMapHierarchyBuilder(); this.siteMapNodeHelperFactory = this.ResolveSiteMapNodeHelperFactory(); this.siteMapNodeVisitor = this.ResolveSiteMapNodeVisitor(settings); this.siteMapXmlNameProvider = new SiteMapXmlNameProvider(); this.attributeAssemblyProviderFactory = new AttributeAssemblyProviderFactory(); this.mvcSiteMapNodeAttributeDefinitionProvider = new MvcSiteMapNodeAttributeDefinitionProvider(); this.siteMapNodeProvider = this.ResolveSiteMapNodeProvider(settings); this.siteMapBuiderSetStrategy = this.ResolveSiteMapBuilderSetStrategy(settings); var siteMapFactoryContainer = new SiteMapFactoryContainer(settings, this.mvcContextFactory, this.urlPath); this.siteMapFactory = siteMapFactoryContainer.ResolveSiteMapFactory(); this.siteMapCreator = new SiteMapCreator(this.siteMapCacheKeyToBuilderSetMapper, this.siteMapBuiderSetStrategy, this.siteMapFactory); }
public CacheDetails(TimeSpan absoluteCacheExpiration, TimeSpan slidingCacheExpiration, ICacheDependency cacheDependency) { this.absoluteCacheExpiration = absoluteCacheExpiration; this.slidingCacheExpiration = slidingCacheExpiration; this.cacheDependency = cacheDependency; }
public void Add(object key, object value, DateTime absoluteExpiration, ICacheDependency dependency, ObjectCacheItemRemovedCallback callback) { if (key == null) { throw new ArgumentNullException("key"); } CacheItem item = this.Wrap(key, value); if (absoluteExpiration != DateTime.MaxValue) { item.AbsoluteExpiration = absoluteExpiration.AddSeconds(-1.0); } if (dependency != null) { item.Dependency = dependency; } if (callback != null) { item.Callback = callback; } this.Add(item); }
/// <summary> /// ���һ��������� /// </summary> /// <param name="key">������Ľ�ֵ</param> /// <param name="value">����Ķ���</param> /// <param name="cacheDependency">������Ĺ��ڲ���</param> public void Add(string key, object value, ICacheDependency cacheDependency) { this.IsInit(); CacheItem item = (CacheItem)this.cacheStorage[key]; if(item == null) { item = new CacheItem(key, value, cacheDependency); } else { item.Value = value; } this.cacheStorage[key] = item; }
/// <summary> /// 创建存储项实体 /// </summary> /// <param name="key">健值</param> /// <param name="value">实际缓存的对象</param> /// <param name="cacheDependency">过期依赖</param> /// <returns>存储项实体</returns> ICacheItem ICacheStorage.CreateCacheItem(string key, object value, ICacheDependency cacheDependency) { return this.CacheStorage.CreateCacheItem(key, value, cacheDependency); }
public void AddObjectWithDepend(string objId, object o, ICacheDependency dep) { if (dep.DependType == EnumDependType.FileDepend) { AddObjectWithFileChange(objId, o, dep.Dependkey); } else { AddObjectWithDepend(objId, o, new string []{dep.Dependkey}); } }
/// <summary> /// ��ָ����ֵ���ڲ��������û����ֵ�� /// </summary> /// <param name="key">������Ľ�ֵ</param> /// <param name="cacheDependency">������Ĺ��ڲ���</param> public object this[string key, ICacheDependency cacheDependency] { set { this.Add(key, value, cacheDependency); } }
public bool Set(string key, byte[] value, ICacheDependency dependency) { return _inner.Set(key, PrepareData(value), dependency); }
internal CacheItem(object key, object value, CacheKeyDependency dependency) { if (key == null) { throw new ArgumentNullException("key"); } this._key = key; this._value = value; this._removedReason = ObjectCacheItemRemovedReason.Underused; this._dateCreated = DateTime.UtcNow; this._absoluteExpiration = this._dateCreated.AddSeconds(300.0); this._dependency = dependency; this._callback = null; }
/// <summary> /// 创建 CacheToken /// </summary> /// <param name="cacheDependency">缓存依赖项</param> /// <param name="varyHeader">客户端缓存依赖头</param> /// <param name="typeName">缓存标记类别名称</param> /// <param name="tokens">用于标识的字符串</param> /// <returns>创建的 CacheToken</returns> public static CacheToken CreateToken( string typeName, ICacheDependency cacheDependency, string varyHeader, string[] tokens ) { if ( typeName == null ) throw new ArgumentNullException( "typeName" ); if ( tokens == null ) throw new ArgumentNullException( "tokens" ); return new CacheTokenItem( typeName, tokens, cacheDependency, varyHeader ); }
public bool Add(string key, string value, ICacheDependency dependency) { return _inner.Add(key, PrepareData(value), dependency); }
public bool Add(string key, string value, DateTime absoluteExpiration, ICacheDependency dependency) { return _inner.Add(key, PrepareData(value), absoluteExpiration, dependency); }
public bool Add(string key, string value, TimeSpan slidingExpiration, ICacheDependency dependency) { return _inner.Add(key, PrepareData(value), slidingExpiration, dependency); }
public void Add(object key, object value, DateTime absoluteExpiration, ICacheDependency dependency) { this.Add(key, value, absoluteExpiration, dependency, null); }
public bool Set(string key, byte[] value, DateTime absoluteExpiration, ICacheDependency dependency) { return _inner.Set(key, PrepareData(value), absoluteExpiration, dependency); }
public bool Set(string key, byte[] value, TimeSpan slidingExpiration, ICacheDependency dependency) { return _inner.Set(key, PrepareData(value), slidingExpiration, dependency); }
public void AddCacheDependency(ICacheDependency cacheDependency) { if (_dependencies == null) { _dependencies = new List<ICacheDependency>(); } _dependencies.Add(cacheDependency); }
public CacheTokenItem( string type, string[] tokens, ICacheDependency cacheDependency, string varyHeader ) { TypeName = type; _tokens = tokens; VaryHeader = varyHeader; }