Database Cache
Automatic Redis acceleration when enabled.
The Core\Database\Cache\Base controller manages Redis-backed document caching, find-result references, pipeline-result references and invalidation. MongoDB remains the persistent source of truth.
Basic implementation
The following illustrates the relevant class relationship. Replace the example classes with your application's concrete types.
// Database cache integration is optional.
// Configure a concrete cache controller before enabling Redis caching.
// The default Core\Database\Cache\Base disables it.
Optional Redis cache
Redis database caching is opt-in: the base cache controller disables it by default. Concrete configuration/implementations decide whether Redis-backed caching is active.
Document cache
Documents can be cached by their Document class and ObjectId. Restoring results prefers already available request-local Collection Documents and then resolves missing Documents from Redis.
Find-result cache
Find results can be stored as references to Documents with Collection revision information, enabling reuse of result sets without repeating the same MongoDB read when valid.
Pipeline-result cache
Cacheable pipeline results retain structured references to typed Documents. The cache controller can restore these references and materialize the corresponding Documents.
Synchronization and invalidation
Written Documents are synchronized and related cached query/pipeline results invalidated. Document-to-result relations and revision handling help prevent stale cached results.
MongoDB remains authoritative
Redis is a performance layer rather than the permanent record. Cache misses, expired entries, disabled caching and unsupported operations can trigger MongoDB access.
Observability
The APPNETOS Debugbar makes MongoDB and Redis operations and their timings inspectable during development; diagnostics are documented in the dedicated Debug component, not as a separate Data & Persistence navigation entry.
Public API Rference
Public methods declared by Core\Database\Cache\Base. Inherited methods are not repeated
here. Signatures follow the uploaded source implementation.
| Method | Description |
|---|---|
public function __construct() |
Constructor |
public function init(): void |
Initialize database cache |
public function aggregateFromCache( array $pipeline, array $options, string
$collectionClassName, ): array|null |
Get aggregate pipeline result from cache |
public function aggregateToCache( array $result, array $pipeline, array $options,
string $collectionClassName, ): void |
Set aggregate pipeline result to cache |
public function findFromCache( array $filter, array $options, string
$documentClassName, ): array|null |
Get find documents from cache |
public function findToCache( object|array|null $result, array $filter, array
$options,
string $documentClassName, ): void |
Cache find documents |
public function syncWrittenDocuments(array $documents): void |
Synchronize written documents to cache |
public function invalidateDocumentsRelations(array $documents): void |
Invalidate written document relations |
public function documentsToCache( array $documents, object|null $redisPipeline =
null,
): void |
Set documents to cache |
public function documentToCache( object $document, object|null $redisPipeline =
null,
): void |
Set document to cache |
public function deleteDocumentsFromCache( array $documents, object|null
$redisPipeline
= null, ): void |
Delete documents from cache |
public function deleteDocumentFromCache( object $document, object|null
$redisPipeline
= null, ): void |
Delete document from cache |