dotnetcore / dotnetcore/EasyCaching
InMemoryCaching: Difference between Set() and Add()
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 336
- PR merge metrics
- No merged PRs in 30d
Description
## 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.