webclient / cache-contract
Interface for caching
Fund package maintenance!
www.paypal.me/ddrv
Patreon
Installs: 1 397
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-12-11 21:11:42 UTC
README
webclient/cache-contract
Cache interface for webclient/ext-cache
Install
composer require webclient/cache-contract:^1.0
Tips and tricks
Split cache storage for settings and responses
You may split cache storage for settings and responses.
implements cache-contract, like it:
<?php use Webclient\Cache\Contract\CacheInterface; class SplitCache implements CacheInterface { private CacheInterface $settingsCache; private CacheInterface $responsesCache; public function __construct(CacheInterface $settingsCache, CacheInterface $responsesCache) { $this->settingsCache = $settingsCache; $this->responsesCache = $responsesCache; } public function get(string $key) : ?string { $this->getStorage($key)->get($key); } public function set(string $key,string $data,?int $ttl = null) : void { $this->getStorage($key)->get($key, $data, $ttl); } private function getStorage(string $key): CacheInterface { if (strpos($key, 'http.settings.') === 0) { return $this->settingsCache; } if (strpos($key, 'http.response.') === 0) { return $this->responsesCache; } throw new InvalidArgumentException('can not define storage'); } }