SimpleCacheManager class final

A composite registry and coordinator for multiple CacheManager implementations within JetLeaf.

The SimpleCacheManager acts as the central orchestrator for all cache managers detected in the JetLeaf dependency context. It serves as both a CacheManager, CacheStorageRegistry and a CacheManagerRegistry, unifying access, discovery, and lifecycle management across heterogeneous caching infrastructures.

Overview

JetLeaf supports modular cache infrastructures, where various application modules or plugins may define their own CacheManager pods. This composite:

  • Discovers all CacheStorage and CacheConfigurer pods through the ConfigurableListablePodFactory.
  • Registers them in deterministic order via AnnotationAwareOrderComparator.
  • Delegates cache operations to an internal _OrderedCacheManager to ensure predictable resolution precedence.

Core Responsibilities

  1. Automatically discovers all CacheStorage and CacheConfigurer pods from the JetLeaf application context upon initialization.
  2. Registers them into a synchronized composite registry via addManager.
  3. Serves as a unified gateway for cache lookup, lifecycle management, and global cache operations such as clearAll and destroy.

Configuration & Discovery

The composite leverages the PodFactoryAware and InitializingPod contracts to perform eager initialization and configuration:

  • On startup, onReady locates and orders all CacheManager instances.
  • Any registered CacheConfigurer pods are invoked to allow custom programmatic adjustments to the composite itself.
  • Each manager is wrapped into an _OrderedCacheManager delegate to preserve deterministic cache resolution ordering.

Thread Safety

Manager registration and mutation of the internal registry are performed under synchronized blocks to prevent race conditions during concurrent startup or configuration changes.

Example

final composite = CompositeCacheManager();
composite.setPodFactory(appContext.getPodFactory());

await composite.onReady();

final userCache = await composite.getCache('users');
await userCache?.put('42', user);
  • CacheManager: The core caching interface implemented by all managers.
  • CacheConfigurer: Allows customization of cache configurations at startup.
  • CacheManagerRegistry: Defines registration behavior for cache managers.
  • PodFactoryAware: Enables factory injection and discovery.
  • InitializingPod: Lifecycle callback for post-construction setup.
  • _OrderedCacheManager: Delegates operations to multiple managers in order.
Implemented types

Constructors

SimpleCacheManager()
A composite registry and coordinator for multiple CacheManager implementations within JetLeaf.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addCreator(CacheStorageCreator createIfNotFound) → void
Registers a fallback cache storage creator used when a requested storage name is not found in the registry.
override
addManager(CacheManager cacheManager) → void
Registers a CacheManager pod with this registry.
override
addStorage(CacheStorage cacheStorage) → void
Registers a CacheStorage instance within the registry.
override
clearAll() FutureOr<void>
Clears all caches managed by this cache manager.
override
destroy() FutureOr<void>
Destroys all caches and releases resources.
override
getCache(String name) FutureOr<CacheStorage?>
Retrieves a cache by name.
override
getCacheNames() FutureOr<Iterable<String>>
Returns the names of all caches managed by this cache manager.
override
getPackageName() String
Represents an abstraction for identifying the package that an object, resource, or service belongs to.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onReady() Future<void>
Interface to be implemented by pods that require initialization logic after their properties have been set by the container.
setApplicationContext(ApplicationContext applicationContext) → void
Sets the ApplicationContext that this component runs in.
setPodFactory(PodFactory podFactory) → void
Sets the PodFactory that created and manages this component.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited