memorycache

Why do I need to call twice the Set on my size limited MemoryCache when I hit the size limit?

风流意气都作罢 提交于 2021-02-07 19:10:49
问题 We are about to use the built-in in-memory cache solution of ASP.NET Core to cache aside external system responses. (We may shift from in-memory to IDistributedCache later.) We want to use the Mircosoft.Extensions.Caching.Memory's IMemoryCache as the MSDN suggests. We need to limit the size of the cache because by default it is unbounded. So, I have created the following POC application to play with it a bit before integrating it into our project. My custom MemoryCache in order to specify

Why do I need to call twice the Set on my size limited MemoryCache when I hit the size limit?

倖福魔咒の 提交于 2021-02-07 19:08:36
问题 We are about to use the built-in in-memory cache solution of ASP.NET Core to cache aside external system responses. (We may shift from in-memory to IDistributedCache later.) We want to use the Mircosoft.Extensions.Caching.Memory's IMemoryCache as the MSDN suggests. We need to limit the size of the cache because by default it is unbounded. So, I have created the following POC application to play with it a bit before integrating it into our project. My custom MemoryCache in order to specify

Rails 5.2.1 - Model & Fragment Caching

和自甴很熟 提交于 2021-01-29 09:23:20
问题 I am trying to setup Model and Fragment Caching in Rails 5.2.1 I have had success with Fragment caching, but I am still seeing database queries after implementing model caching for my Model. I have enabled development caching $ rails dev:cache Model Helper module LanguagesHelper def approved_languages Rails.cache.fetch("approved_languages") { Languages.is_active.is_approved } end end Controller class LanguagesController < ApplicationController include LanguagesHelper def index @languages =

Using MemoryCache with HostFileChangeMonitor init to a directory gets ArgumentOutOfRangeException

ぐ巨炮叔叔 提交于 2021-01-27 05:23:25
问题 I am using MemoryCache from System.Runtime.Caching of .NET 4 and I wish to invalidate the cache entry when a directory changes. HostFileChangeMonitor is supposed to handle both files and directories so I am adding it like so: var cacheItemPolicy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(30) }; cacheItemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List<string> { folder })); but then I get an exception: System.ArgumentOutOfRangeException: The UTC time

Stop Reentrancy on MemoryCache Calls

你离开我真会死。 提交于 2021-01-20 04:13:47
问题 The app needs to load data and cache it for a period of time. I would expect that if multiple parts of the app want to access the same cache key at the same time, the cache should be smart enough to only load the data once and return the result of that call to all callers. However, MemoryCache is not doing this. If you hit the cache in parallel (which often happens in the app) it creates a task for each attempt to get the cache value. I thought that this code would achieve the desired result,

Unexpected “Cache entry must specify a value for Size when SizeLimit is set” message in AspNetCore 3

时间秒杀一切 提交于 2020-08-04 05:20:33
问题 So this all worked fine before updating to AspNetCore 3 today. I am using a memory cache with dependency injection ( IMemoryCache cache ). I add it to my middleware with services.AddMemoryCache(); and do NOT set a size, but I still end up with the error message: Cache entry must specify a value for Size when SizeLimit is set. When I inspect the instance of MemoryCache and it does indeed have a size of 10240 set (see image). The problem is I've been looking for a hour and I have no clue where

What's the difference between MemoryCache.Add and MemoryCache.Set?

狂风中的少年 提交于 2020-01-30 19:28:06
问题 I read the MSDN documentation but didn't really understand it. I believe that the behavior of Set is "replace existing, or add" (atomically). Is that correct? 回答1: Add does nothing (returns false ) if there is already a value for that key. Set does an insert or update, as necessary. Remove + Add would leave a gap in the middle when another thread querying that key would get no clue ( Set does not; the swap is typically atomic); as such, while Set has the same end result as Remove + Add , the

Memory Cache .Net 4.0 performance test : astonishing result

亡梦爱人 提交于 2020-01-27 20:57:31
问题 This performance test is wrong or the system cache is working with exceptional performance? This is my result : [13] number of interactions 100000 : 63 milliseconds [14] number of interactions 100000 : 139 milliseconds [12] number of interactions 100000 : 47 milliseconds [15] number of interactions 100000 : 44 milliseconds End of test. Hardware : x86 Family 6 Model 23 Stepping GenuineIntel ~2992 Mhz 3.327 MB, 5.1.2600 Service Pack 3 using System; using System.Collections.Generic; using System