Skip to content

In-memory cache timespan not working#26

Description

@eaidland

Hi!
First of all thanks for a great package 馃

Version: DoubleCache 2.0.0-beta8 (Nuget).

When calling our API we have a middelware that uses DoubleCache. The idea is to get key from in-memory, then redis and if non then fetch from keyvault. We have set the absolute expiration to 1 minute.

  1. First run get the value from KeyVault, since the key isn't in in-mem nor redis.
  2. Saves value (encryptet) to in-mem and redis.
  3. Second run fetches from in-mem.
  4. Server restart
  5. Third run fetches from redis, then save in mem.
  6. Change secret in KeyVault
  7. Wait for the absolute expiration (over 1 min)
  8. Fourth run the in-mem still remembers the old value

Our conclution is that the local memory doesn't respect the expiration value.

string value = await _cache.GetAsync("mykey", async () => await _myService.GetKeyValue(myValue), TimeSpan.FromMinutes(1));

To get the solution to work we had to override the MemoryCache.Default

System.Runtime.Caching.MemoryCache.Default.Set("mykey", value, DateTimeOffset.UtcNow.AddMinutes(1));

So is this a bug or are we using the package wrong?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions