public async Task SetCourseBySlugAsync(CourseViewDTO course) { var idCacheKey = await EnsureCourseCacheKey(course.Id.Value); var cacheKey = $"{nameof(CoursesController)}_{nameof(CoursesController.GetCourseBySlug)}_{course.CourseDef.Slug}"; await cache.SetStringAsync( cacheKey, jsonSerializer.Serialize(course), ExtendedDistributedCacheEntryOptions.New.AddDependencyKey(CacheKeyDependency.WithKey(idCacheKey)) ); }
private async Task <string> EnsureCourseCacheKey(Guid courseId) { await EnsureCoursesMasterCacheKey(); var idCacheKey = $"{nameof(Course)}_{courseId}"; var data = await cache.GetAsync(idCacheKey); if (data is null) { await cache.SetAsync( idCacheKey, new byte[0], ExtendedDistributedCacheEntryOptions.New .AddDependencyKey(CacheKeyDependency.WithKey(coursesMasterCacheKey)) ); } return(idCacheKey); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); var parentControl = (Parent as BasePartialCachingControl); if (parentControl == null) { return; } if (EnableCaching) { parentControl.CachePolicy.Duration = CacheDuration; if (!string.IsNullOrEmpty(CacheVaryByControl)) { parentControl.CachePolicy.VaryByControl = CacheVaryByControl; } if (!string.IsNullOrEmpty(CacheVaryByCustom)) { parentControl.CachePolicy.SetVaryByCustom(CacheVaryByCustom); } if (!string.IsNullOrEmpty(CacheKeyDependency)) { string[] cacheKeys = CacheKeyDependency.Split(','); // add cache dependency keys if they aren't already in cache foreach (string cacheKey in cacheKeys) { if (Cache.Get(cacheKey) == null) { Cache.Add(cacheKey, string.Empty, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } } // add key dependency parentControl.CachePolicy.Dependency = new CacheDependency(null, cacheKeys); } } else { parentControl.CachePolicy.Cached = false; } }
public async Task SetCoursesRefAsync(List <CourseEditDTO> courses) { var cacheKey = $"{nameof(CoursesController)}_{nameof(CoursesController.GetCoursesRef)}"; await EnsureCoursesMasterCacheKey(); await cache.SetStringAsync(cacheKey, jsonSerializer.Serialize(courses), ExtendedDistributedCacheEntryOptions.New.AddDependencyKey(CacheKeyDependency.WithKey(coursesMasterCacheKey))); }
public async Task SetCourseMembersAsync(Guid courseId, List <UserDTO> members) { var idCacheKey = await EnsureCourseCacheKey(courseId); var cacheKey = $"{nameof(CoursesController)}_{nameof(CoursesController.GetCourseMembers)}_{courseId}"; await cache.SetStringAsync(cacheKey, jsonSerializer.Serialize(members), ExtendedDistributedCacheEntryOptions.New.AddDependencyKey(CacheKeyDependency.WithKey(idCacheKey)) ); }
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; }