FusionCache icon indicating copy to clipboard operation
FusionCache copied to clipboard

[FEATURE] Improve testing integration via fakes

Open saithis opened this issue 2 months ago • 0 comments

Problem

I want to write tests that actually cover the caching and can use TimeProvider to jump forward in time to not have to wait for the expiration. I also would like to see if failsafe was triggered or not, etc. But I can't use a real distributed cache in the tests.

Currently - as far as I know - there is only support for in memory cache + NullDistributedCache, which completelly disables the L2 cache.

Solution

A fake distributed cache, that:

  • stores values in a concurrent dictionary
  • uses TimeProvider to reason about expiration
  • remembers all cache reads/write calls
  • has methods to get the remembered reads/writes
  • has methods to get the metadata of a cache value (when does it expire, tags, etc.)
  • has a reset method (to revert to an empty state between tests)

If possible something similar for the in memory cache.

Alternatives

I couldn't come up with good alternatives.

Additional context

saithis avatar Oct 20 '25 07:10 saithis