/// <summary> /// Initializes a new instance of the <see cref="ValidationContext{TValue}"/> class. /// </summary> /// <param name="cacheSection">Cache section descriptor.</param> /// <param name="value">Value to check.</param> /// <param name="metadata">Metadata.</param> public ValidationContext(ICacheSectionDescriptor <TValue> cacheSection, TValue value, IMutablePropertyContainer metadata) { CacheSection = cacheSection; Value = value; Metadata = metadata; ShouldCache = true; }
/// <summary> /// Initializes a new instance of the <see cref="CacheSection{TValue}"/> class. /// </summary> /// <param name="sectionName">Section name.</param> /// <param name="memoryCache">Provided memory cache.</param> /// <param name="configureCacheEntry">External configure function.</param> /// <param name="settings">Cache settings.</param> public CacheSection( [NotNull] string sectionName, [NotNull] IMemoryCache memoryCache, Action <ICacheEntryContext>?configureCacheEntry = null, ICacheSettings <TValue>?settings = null) { sectionName.AssertArgumentNotNull(nameof(sectionName)); _cacheSectionDescriptor = new CacheSectionDescriptor <TValue>(sectionName, settings ?? CacheSettings <TValue> .Default); _memoryCache = memoryCache.AssertArgumentNotNull(nameof(memoryCache)); _configureCacheEntry = configureCacheEntry; }
/// <summary> /// Initializes a new instance of the <see cref="CacheResult{TValue}"/> struct. /// </summary> public CacheResult( ICacheSectionDescriptor <TValue> cacheSection, string key, TValue value, Message?error, IPropertyContainer metadata, CacheHitMiss hitMiss, bool isCached) { SectionName = cacheSection.SectionName; Settings = cacheSection.CacheSettings; Key = key; Value = value; Error = error; Metadata = metadata; HitMiss = hitMiss; IsCached = isCached; }
public static IEnumerable <T> GetAllValues <T>([NotNull] this CacheManager cacheManager, [NotNull] ICacheSectionDescriptor <T> sectionDescriptor) { cacheManager.AssertArgumentNotNull(nameof(cacheManager)); sectionDescriptor.AssertArgumentNotNull(nameof(sectionDescriptor)); var cacheSection = cacheManager.GetOrCreateSection(sectionDescriptor); return(cacheSection.GetAllValues()); }
/// <summary> /// Initializes a new instance of the <see cref="CacheEntryContext"/> class. /// </summary> /// <param name="cacheSection">Cache section descriptor.</param> /// <param name="cacheEntry">Cache entry to configure.</param> public CacheEntryContext(ICacheSectionDescriptor cacheSection, ICacheEntry cacheEntry) { CacheSection = cacheSection; CacheEntry = cacheEntry; Metadata = new MutablePropertyContainer(); }
/// <summary> /// Initializes a new instance of the <see cref="ErrorHandleContext{TValue}"/> class. /// </summary> /// <param name="cacheSection">Cache section descriptor.</param> /// <param name="exception">Exception raised in factory method.</param> /// <param name="metadata">Allows to set metadata for cache entry.</param> public ErrorHandleContext(ICacheSectionDescriptor <TValue> cacheSection, Exception exception, IMutablePropertyContainer metadata) { CacheSection = cacheSection; Exception = exception; Metadata = metadata; }
/// <summary> /// Gets or creates cache section by provided settings. /// </summary> /// <typeparam name="TValue">Value type.</typeparam> /// <param name="sectionDescriptor">CacheSectionDescriptor.</param> /// <returns>Cache section.</returns> public ICacheSection <TValue> GetOrCreateSection <TValue>(ICacheSectionDescriptor <TValue> sectionDescriptor) { ICacheSection cacheSection = _sections.GetOrAdd(sectionDescriptor.SectionName, sectionName => CreateCacheSection(sectionName, sectionDescriptor.CacheSettings)); return((ICacheSection <TValue>)cacheSection); }
/// <summary> /// Gets or creates value according cache section settings. /// </summary> /// <typeparam name="TValue">Value type.</typeparam> /// <param name="sectionDescriptor">Section descriptor.</param> /// <param name="key">Cache key.</param> /// <param name="factory">Factory method to create and customize cache item.</param> /// <returns><see cref="CacheResult{TValue}"/>.</returns> public async Task <CacheResult <TValue> > GetOrCreateAsync <TValue>(ICacheSectionDescriptor <TValue> sectionDescriptor, string key, Func <ICacheEntryContext, Task <TValue> > factory) { var cacheSection = GetOrCreateSection(sectionDescriptor); return(await cacheSection.GetOrCreateAsync(key, factory)); }