New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netcore GetOrAdd doesn't work with SizeLimit set #38
Comments
Any updates/workaround on this? |
Yeah this is indeed a bug, LazyCache cannot support the size limit feature currently. I will be really tough to fix because of the API design, we cannot easily support Lazy initialisation and calling SetSize at the right time. May need to offer a workaround like extra optional arguments to set size directly. Doubt i am gonna have a chance to look at this in the near future but open to sugestions and PRs. |
This would be very helpful. I wouldn't mind if you set the initial size of the task/lazy to 1, and then updated the policy later (if that's allowed) |
I ran into a similar issue with EFCore - which some some reason sets a size on the global It's SUPER puzzling to me that EF Core thinks it OK to do this. Anyway I just made my own implementation to make a non-SizeLimit cache.
Then add these:
|
as @SirJosh3917 said - just setting it to 1 would help - as knowing the actual size of the cached object it impossible before the actual creation and even then it's very likely it will be an estimate anyways.. so maybe just go:
|
This is fixed in LazyCache 2.1 because we now allow you to pass the MemoryCacheEntryOptions so they are set on the cache entry object before the cached func is lazily evaluated. The following should now work fine: cacheWithSizeLimit.GetOrAdd("key2", () => "item2", new MemoryCacheEntryOptions().SetSize(1)); |
This create new entry in cache for a key every time. |
but this does not set the sizeLimit of the overall cache, it sets the size of the cache object being added |
Hi alastairtree,
We have tried setting the SizeLimit on the cache using the .netcore version of IAppCache, and it doesn't set the size on the entry before GetOrCreate is called on the provider.
We think this is because of the use of the Lazy in GetOrAdd in the CachingService.cs
Here is some test code which fails for GetOrAdd (but works for Add):
When we test the calls to MemoryCacheProvider directly, it fails only when a lazy is passed to GetOrCreate, we believe because it's using a Lazy it's not executing the call back to SetOptions on the entry.
The example below works for item1 and item2 but not item3.
The text was updated successfully, but these errors were encountered: