Skip to content
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

InMemoryCaching: Difference between Set() and Add() #551

Open
ricsiLT opened this issue Sep 27, 2024 · 0 comments
Open

InMemoryCaching: Difference between Set() and Add() #551

ricsiLT opened this issue Sep 27, 2024 · 0 comments

Comments

@ricsiLT
Copy link

ricsiLT commented Sep 27, 2024

Description

Why is there a difference between these two methods? What are the uses for them? From testing I see that one of them increments the _cacheSize and the other one doesn't. Why is that?

Related code

        var maxSize = 50_000;
        var cacheOptions = new InMemoryCachingOptions
        {
            SizeLimit = maxSize,
            ExpirationScanFrequency = 1
        };
        var cache = new InMemoryCaching("default", cacheOptions);
        foreach (var i in Enumerable.Range(1, maxSize))
        {
            cache.Add(i.ToString(), i);
        }

        foreach (var i in Enumerable.Range(maxSize, 10))
        {
            cache.Set(i.ToString(), i);
        }

        cache.Set("50011", 11);
        await Task.Delay(6000); // Just in case expiration cleanup is in progress??

        Assert.NotNull(cache.Get("50011"));
        Assert.Null(cache.Get("1")); // I'd expect this key to be missing, but it's not??

Expected behavior: [What you expected to happen]

Regardless of .Add() or .Set(), SizeLimit should be honored.

Actual behavior: [What actually happened]

When using .Set(), size limit is honored.
When using .Add(), size limit is ignored.

Specifications

    <PackageReference Include="EasyCaching.InMemory" Version="1.9.2" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant