Metalama.Patterns.Caching
A caching front-end that can be plugged different backends and helps with building the cache key, coping with special return types, invalidating the cache (directory or with dependencies). This package does not require the Metalama Aspect Framework.
Install
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard | |
| Other |
README
About
The Metalama.Patterns.Caching package is a front-end library for caching. It simplifies caching method results and invalidating the cached results.
This package is designed for use with the Metalama.Patterns.Caching.Aspects package, which offers Metalama-based aspects for caching, cache invalidation, and cache key generation. However, the Metalama.Patterns.Caching package does not rely on the Metalama aspect framework, and it can be used independently or with another aspect framework.
Key Features
- Caching the return value of a method as a function of its arguments.
- Invalidation of cached method results, both directly and indirectly through cache dependencies.
- In-memory cache, Redis cache, Pub/Sub synchronized cache, L2 in-memory cache.
- Caching profiles for dynamically changing settings at runtime.
- Automatic reload of expired cached items.
- Cache key formatters through the
Flashtrace.Formatterspackage. - Value adapters for caching "special" types like streams or enumerables.
- Locking to prevent concurrent execution.
This package can interact with any cache implementation. The abstraction is provided by the CachingBackend class from the Metalama.Patterns.Caching.Backend package.
Main Types
The primary types in this package are:
- ICachingService is the main interface.
- CachingService is the primary implementation of
ICachingServiceand should generally not be directly used unless you are not using dependency injection. - CachingServiceFactory extends
IServiceCollectionand allows the addition ofICachingServiceto your application. - CachedMethodMetadata represents the metadata of a cached method. If you are not using an aspect framework, you must create an instance of this class for each cached method.
- CacheKeyBuilder is the algorithm that generates the cache key based on the method metadata and its arguments.
- IValueAdapter is the abstraction for caching special types like streams or enumerables.
Additional Documentation
Related Packages
Metalama.Patterns.Caching.Aspectsprovides an aspect-oriented API for the current package.Metalama.Patterns.Caching.Backenddefines the CachingBackend abstraction and provides core implementations for in-memory and multi-layered caching.Metalama.Patterns.Caching.Backends.Redisoffers theCachingBackendimplementation for Redis.Metalama.Patterns.Caching.Backends.Azureimplements pub/sub synchronization of distributed in-memory caches through Azure Message Bus.Flashtrace.Formattersprovides an infrastructure for cache key formatting.
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.