-
Notifications
You must be signed in to change notification settings - Fork 1
6. Customization
Vladyslav Lobyntsev edited this page Mar 5, 2024
·
2 revisions
- Implement the following interface
public interface ICacheImplementation
{
ValueTask<TEntity?> RetrieveAsync<TEntity>(string key);
ValueTask CacheAsync<TEntity>(string key, TEntity entity, CacheOptions options) where TEntity : notnull;
ValueTask RemoveAsync(string key);
}
- Call StoreIn with the custom cache implementation instance to configure the custom cache implementation for the particular entity, or SetGenericCache to configure the custom cache implementation globally.
To use a custom distributed cache storage format (JSON is used by default) for a particular entity (or for many entities, depending on CanBeUsedForType implementation)
- Implement the following interface
public interface IDistributedCacheSerializer
{
ValueTask<byte[]> SerializeAsync<TEntity>(TEntity entity);
ValueTask<TEntity?> DeserializeAsync<TEntity>(byte[] bytes);
bool CanBeUsedForType(Type type);
}
- For non-ASP.NET applications, pass the serializer(s) object to StoreInDistributedCache or SetDistributedAsDefaultCache method.
- For ASP.NET application, register serializer(s) in ASP.NET DI container.