adachsoft / content-source-cache
A caching decorator and cache stores for content source providers.
v0.1.0
2026-11-22 16:18 UTC
Requires
- php: ^8.3
- adachsoft/content-source-contracts: ^0.1.0
- psr/clock: ^1.0
Requires (Dev)
- adachsoft/content-source-contract-tests: ^0.1.0
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-22 15:20:52 UTC
README
A caching layer for applications that retrieve source documents through the adachsoft/content-source-contracts provider interface. It reduces repeated provider requests while preserving the existing source-provider contract.
Features
CachingSourceProviderdecorates a source provider and caches successful document collections for a configurable time-to-live.SourceCacheKeyFactorycreates deterministic keys from the provider, entity, locale, and an optional configuration namespace.InMemorySourceDocumentCacheprovides process-local storage, whileJsonFileSourceDocumentCachepersists entries as JSON files using atomic writes.- Cache entries retain their retrieval timestamps. Expired or unreadable JSON entries are treated as cache misses, and failed provider requests are not cached.
Requirements
- PHP 8.3 or later.
- Composer for installing the library and its dependencies.
Installation
composer require adachsoft/content-source-cache
Usage
Create or obtain a provider that implements SourceProviderInterface, a PSR-20 clock, and a cache store. Use a distinct namespace when provider configuration affects the returned documents.
use AdachSoft\ContentSourceCache\CachingSourceProvider;
use AdachSoft\ContentSourceCache\JsonFileSourceDocumentCache;
use AdachSoft\ContentSourceCache\SourceCacheKeyFactory;
$cachingSourceProvider = new CachingSourceProvider(
sourceProvider: $sourceProvider,
sourceDocumentCache: new JsonFileSourceDocumentCache('/var/cache/my-app/sources'),
sourceCacheKeyFactory: new SourceCacheKeyFactory(),
clock: $clock,
ttlSeconds: 3600,
cacheNamespace: 'wikipedia:en',
);
$documents = $cachingSourceProvider->fetch($entity, 'en');
See the usage example for the cache-store options and configuration guidance.