MetalamaAPI documentationPatterns APIMetalama.​Patterns.​Caching.​BackendsMemory­Caching­Backend­ConfigurationSerializer
Open sandboxFocus

MemoryCachingBackendConfiguration.Serializer Property


Gets or sets an optional ICachingSerializer. By default, this property is null, and cached objects are referenced in the as is, without any serialization. Setting this property forces the cache to hold the serialized representation of the cached object.

public ICachingSerializer Serializer { get; set; }
Property Value
Type Description

Using a serializer for the in-memory cache can have two benefits.

First, it allows to test the readiness of the code before switching to a distributed cache like Redis. Running a Redis server on a development machine is less convenient than running no server, so using an in-memory caching backend with serializer is a good comprise between test coverage and convenience.

Second, it allows to cache mutable objects and make sure that every caller receives a fresh instance of the return value of the cached method.