ASP.NET Core – Cache memory cache (Part 2)

ASP.NET Core – Cache memory cache (Part 2) Continuing from the previous article ASP.NET Core – Memory Cache of Cache (Part 1), so the directory here starts from 2.4. 2.4 MemoryCacheEntryOptions MemoryCacheEntryOptions is a memory cache configuration class through which cache-related strategies can be configured. In addition to the expiration time mentioned above, we can also set the following: Set cache priority. Sets the PostEvictionDelegate that is called after an entry is evicted from the cache. The callback runs on a different thread than the code that removes the item from the cache. Limit cache size var memoryCacheEntryOption = new MemoryCacheEntryOptions(); memoryCacheEntryOption.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3); // Cache priority, Low, Normal, High, NeverRemove, Normal is the default value, which is related to the cache deletion strategy memoryCacheEntryOption.SetPriority(CacheItemPriority.Normal); //Register cache item deletion callback event memoryCacheEntryOption.RegisterPostEvictionCallback(PostEvictionDelegate); _cache.Set(CacheKey, cacheValue, memoryCacheEntryOption); public void PostEvictionDelegate(object cacheKey, object cacheValue, EvictionReason evictionReason, object state) { var memoryCache = (IMemoryCache)state; Console.WriteLine($”Entry {cacheKey}:{cacheValue} was evicted: {evictionReason}.”); } The cache size limit is used in conjunction with the configuration of the MemoryCache instance. MemoryCache instances can optionally specify and enforce size limits. There is no defined unit of measurement for cache size limits because caches have no mechanism for measuring entry size.…

ASP.NET Core – Cache memory cache (Part 2)

ASP.NET Core – Cache Memory Cache (Part 2) Continued from the previous article ASP.NET Core – Cache Memory Cache (Part 1), so the directory here starts from 2.4. 2.4 MemoryCacheEntryOptions MemoryCacheEntryOptions is a memory cache configuration class through which you can configure cache-related strategies. In addition to the expiration time mentioned above, we can also set the following: Set cache priority. Sets the PostEvictionDelegate that is called after an entry has been evicted from the cache. The callback runs on a different thread than the code that removes the item from the cache. Limit cache size var memoryCacheEntryOption = new MemoryCacheEntryOptions(); memoryCacheEntryOption.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3); // Cache priority, Low, Normal, High, NeverRemove, Normal is the default value, which is related to the strategy of cache deletion memoryCacheEntryOption. SetPriority(CacheItemPriority. Normal); // Register cache item deletion callback event memoryCacheEntryOption. RegisterPostEvictionCallback(PostEvictionDelegate); _cache.Set(CacheKey, cacheValue, memoryCacheEntryOption); public void PostEvictionDelegate(object cacheKey, object cacheValue, EvictionReason evictionReason, object state) { var memoryCache = (IMemoryCache)state; Console.WriteLine($”Entry {cacheKey}:{cacheValue} was evicted: {evictionReason}.”); } The cache size limit is used in conjunction with the configuration of the MemoryCache instance. A MemoryCache instance can optionally specify and enforce a size limit. There is no defined unit of measure for the cache size limit, because…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索