PostSharp6.0/Caching/Caching Back-Ends/Using In-Memory Cache

Using In-Memory Cache

For local, in-memory caching, PostSharp relies on the MemoryCache class of the .NET Framework.

To use the MemoryCache class to store cached values in memory, assign an instance of a MemoryCachingBackend class to CachingServices.DefaultBackend property.

C#
CachingServices.DefaultBackend = new MemoryCachingBackend();

By default, the MemoryCache.Default is used. To use other instance of the MemoryCache than the default one, an instance of the MemoryCache class can be passed to the constructor of the MemoryCachingBackend class.

C#
MemoryCache cache = new MemoryCache( "myCache" );
CachingServices.DefaultBackend = new MemoryCachingBackend( cache );

See MSDN for details on the MemoryCache class.