Cache entry must specify a value for Size
See original GitHub issueThis should be a fairly easy one to knock out, but I’m not seeing a way to set the ‘Size()’ of an item for the MemoryCacheRateLimitCounterStore and other MemoryCache* providers, for when memory cache’s SizeLimit is set.
System.InvalidOperationException: Cache entry must specify a value for Size when SizeLimit is set.
at Microsoft.Extensions.Caching.Memory.MemoryCache.SetEntry(CacheEntry entry)
at Microsoft.Extensions.Caching.Memory.CacheEntry.Dispose()
I think “Size = 1” can be added here: https://github.com/stefanprodan/AspNetCoreRateLimit/blob/c5a4f28010d8a7db9c095633573d4b80ce685dbf/src/AspNetCoreRateLimit/Store/MemoryCacheRateLimitStore.cs#L43
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Cache entry must specify a value for Size when SizeLimit is ...
Unexpected "Cache entry must specify a value for Size when SizeLimit is set" message in AspNetCore 3. So this all worked fine before...
Read more >Cache in-memory in ASP.NET Core
SizeLimit doesn't have units. Cached entries must specify size in whatever units they consider most appropriate if the cache size limit has been ......
Read more >Simple C# MemoryCache implementation – Understand the ...
Each cache entry you insert must specify a size (integer). The MemoryCache will then hold entries until that limit is met. Example:
Read more >In Memory Caching on .NET 6.0 - Nishān Wickramarathna
If the cache size limit is set, all entries must specify size. The ASP.NET Core runtime doesn't limit cache size based on memory...
Read more >In-Memory Caching in ASP.NET Core
While using a MemoryCache instance, there is an option to specify a size limit. The cache size limit does not have a defined...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cristipufu yes, exactly; a separate MemoryCache (stored in a separate ServiceProvider instance) without depending on the end-developer to set up a memorycache without a SizeLimit.
@thomasgalliker I think your solution is a reasonable workaround! I will note that it looks like you’re creating two separate instances of the memory cache, which might cause some issues. I would suggest updating your static class to store the cache ones it’s created, then just return the stored cache instead of creating new ones each time.