Skip to content

IVitreousCacheSerializer interface

Namespace: Vitreous.Caching.Abstractions
Assembly: Vitreous.Caching.dll

Converts cached values to and from bytes. Used by both the IDistributedCache backend and the Redis backend.

public interface IVitreousCacheSerializer

The default implementation is SystemTextJsonVitreousCacheSerializer. Register your own implementation before calling AddVitreousCaching() or AddVitreousRedisCaching() to replace it.

Implementations must make [TryDeserialize<T>](/Vitreous/api/vitreous/caching/abstractions/ivitreouscacheserializer/#Vitreous_Caching_Abstractions_IVitreousCacheSerializer_TryDeserialize__1_System_ReadOnlySpan_System_Byte____0__) return false when the data was not written for T, so that two queries that share a cache key but return different types can never read each other's entries.

Serializes value, recording that it is a T.

byte[] Serialize<T>(T value)

value T

byte[]

T

TryDeserialize<T>(ReadOnlySpan<byte>, out T?)

Section titled “ TryDeserialize<T>(ReadOnlySpan<byte>, out T?)”

Deserializes data as a T. Returns false when the data holds a different type or an unrecognised format; callers treat that as a cache miss.

bool TryDeserialize<T>(ReadOnlySpan<byte> data, out T? value)

data ReadOnlySpan<byte>

value T?

bool

T