question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache entry must specify a value for Size

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
onionhammercommented, Oct 12, 2020

@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.

1reaction
mirdakicommented, Oct 1, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found