Repository navigation
Home
CachingServiceWithAOPSupport caches method results for Autofac components. Put [Cache] on a method of the class, register the class with EnableCacheInterception(), and calls made through its interface are answered from System.Runtime.Caching.MemoryCache until the entry expires. The interception is a Castle DynamicProxy interface proxy, created through Autofac.Extras.DynamicProxy. It is not a distributed cache, it makes no network or file access, and it caches nothing that is called on the class itself rather than through the interface.
The current version is 2.0.0, published on nuget.org on 2026-09-28 (UTC). It ships two builds, lib/net10.0 and lib/netstandard2.0; .NET Framework and .NET 8 load the second.
dotnet add package CachingServiceWithAOPSupportA whole Program.cs:
using System;
using Autofac;
using CachingServiceWithAOP;
using CachingServiceWithAOP.Extensions;
var builder = new ContainerBuilder();
builder.RegisterCachingModule();
builder.RegisterType<PriceService>().As<IPriceService>().EnableCacheInterception();
using var container = builder.Build();
var prices = container.Resolve<IPriceService>();
Console.WriteLine(prices.GetPrice("A-1"));
Console.WriteLine(prices.GetPrice("A-1"));
Console.WriteLine(prices.GetPrice("B-2"));
public interface IPriceService
{
decimal GetPrice(string sku);
}
public class PriceService : IPriceService
{
[Cache(0, 10, 0)]
public decimal GetPrice(string sku)
{
Console.WriteLine("loading " + sku);
return sku == "A-1" ? 9.99m : 4.50m;
}
}It prints the same on .NET 10, .NET 8 and .NET Framework 4.8, with the lowest Autofac version the package accepts (6.5.0) and the newest published one (9.3.4):
loading A-1
9.99
9.99
loading B-2
4.50
The second call for A-1 never reached GetPrice: the proxy answered it from the cache, where the result stays for ten minutes.
- Getting started: install it, which build each runtime loads, which Autofac and Castle versions you get.
- API reference: every public type and member, with what it returns and throws.
- How results are cached: the cache key, the shared store, lifetimes, what is kept and what is not.
- Errors and edge cases: every error message, and the setups where nothing gets cached.
- Recipes: a store per test, logging, entries per instance, replacing a value.
- Versions and upgrading: 1.0.0, 1.0.1 and 2.0.0, and moving from 1.x.
- FAQ: short answers that link to the detail.
- Development: build, test, CI and the release steps.
This wiki describes CachingServiceWithAOPSupport 2.0.0 and was last updated on 2026-09-30. The library is MIT licensed. Report problems in the issues. On NuGet: CachingServiceWithAOPSupport.