Search by

adachsoft / content-source-cache

Arkadiusz Adach

A caching decorator and cache stores for content source providers.

Package info

gitlab.com/a.adach/content-source-cache

Issues

pkg:composer/adachsoft/content-source-cache

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-22 16:18 UTC

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

  • CachingSourceProvider decorates a source provider and caches successful document collections for a configurable time-to-live.
  • SourceCacheKeyFactory creates deterministic keys from the provider, entity, locale, and an optional configuration namespace.
  • InMemorySourceDocumentCache provides process-local storage, while JsonFileSourceDocumentCache persists 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.