Skip to content
m4bwav edited this page Oct 1, 2026 · 1 revision

The repository has no issues yet; these are the questions the README, the source and the verification for this wiki raised.

Why does my [Cache] method run on every call?

Check these, in this order:

  1. [Cache] is on the class's method, not only on the interface.
  2. The component is registered with EnableCacheInterception() and resolved as its interface.
  3. The call comes through the proxy, not from inside the class.
  4. The lifetime is above zero.
  5. The method does not return void or ValueTask.
  6. Every argument can be written into a key.

Errors and edge cases shows each case with its output.

Do two instances of my class share cached results?

Yes. The key starts with the instance's ToString(), which by default is the type name, so every instance of a class shares entries, across containers too. Override ToString() to keep them apart (How results are cached).

Do results survive disposing the container?

Yes, with RegisterCachingModule(): the store is MemoryCache.Default, which lives as long as the process. Register a MemoryCacheService over a MemoryCache of your own to tie the store to the container (Recipes).

How do I clear the cache, or remove one entry?

The package has no remove method. An entry leaves when its lifetime ends. For a value you cache by key, Set with the same key replaces it (Recipes). For tests, give each test its own store.

Is the expiry sliding?

No. An entry expires a fixed time after it was stored, however often it is read (How results are cached shows a three-second entry expiring after reads at 1 and 2 seconds).

What if two threads call the method at once?

With the same key, one runs the method and the others wait for its result. With different keys they run in parallel (How results are cached). 1.0.1 ran the method once per caller.

Can I cache async methods?

A method returning Task or Task<T> is cached as its task, and a task that fails or is cancelled is dropped. A method returning ValueTask is not cached (How results are cached).

Which Autofac versions does it work with?

Autofac 6.5.0 and 9.3.4 were run for this wiki, with Autofac.Extras.DynamicProxy 7.1.0 and 8.1.0 and Castle.Core 5.1.1 and 5.2.1 (Getting started). The README says Autofac 6.5 to 9; the versions between the two ends were not run here. The repository's CI runs the same three sets against every build.

Which runtimes and systems was it run on?

.NET Framework 4.8, .NET 8 and .NET 10 were run on Windows 11, and .NET 10 on Ubuntu 26.04 in WSL. The answers were the same everywhere; only .NET Framework words some exception messages differently (Getting started). The package says .NET Framework 4.6.2 and later; versions before 4.8 were not run.

Is it a distributed cache?

No. Entries live in the memory of one process. Nothing is shared between processes or servers, and nothing is written to disk.

Should I use it in new code?

The README advises against it for new code that does not use Autofac: IMemoryCache or HybridCache fit there. Its place is an application already built on Autofac that wants method results cached with an attribute.

Does it make requests or write files?

No. It reads and writes process memory only.

Why do the package and the namespace have different names?

The package id has been CachingServiceWithAOPSupport since 2015, and the assembly and namespaces CachingServiceWithAOP. 2.0.0 kept both so that 1.0.1 code compiles unchanged.

Can I use it from F#?

Not tested.

Is it safe to cache results that belong to one user?

Only with care. The key is built from the arguments and the instance's ToString(), so two users who make the same call get the same entry. Put what tells them apart in the arguments or in ToString(), or do not cache such results.

Clone this wiki locally