Skip to content

CacheStore

Viames Marino edited this page Oct 19, 2026 · 1 revision

Pair framework: CacheStore

Pair\Cache\CacheStore is the backend contract used by Cache and Idempotency. Implement it to provide an application-owned cache store without changing the facade.

Contract

Method Behavior
get(string $key, mixed $default = null): mixed Returns a cached value or the fallback when missing or expired.
set(string $key, mixed $value, ?int $ttlSeconds = null): bool Stores a serializable value; null means no expiration.
has(string $key): bool Checks whether a live entry exists.
delete(string $key): bool Deletes one entry.
clear(): bool Clears entries owned by this store.

Built-in implementations are FileCacheStore, ApcuCacheStore, and RedisCacheStore. See Cache for driver configuration and extension requirements.

Register a store

use Pair\Cache\Cache;
use Pair\Cache\FileCacheStore;

Cache::setStore(new FileCacheStore(TEMP_PATH . 'application-cache'));

Registering a store under AdapterKeys::CACHE only makes it available through the adapter registry; call Cache::setStore($store) to select it for the facade. Idempotency::setStore($store) configures idempotency separately; it does not automatically use the facade's selected store.

The interface has no atomic compare-and-set, increment, or sliding-window operations. Use RateLimiter for concurrent request throttling rather than combining get() and set() yourself.

See also: Cache, Idempotency, AdapterKeys, AdapterRegistry.

Clone this wiki locally