Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Latest Stable VersionTotal DownloadsLicensePHP

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:

<?phpuseWebclient\Cache\Contract\CacheInterface;
class SplitCache implements CacheInterface
{
privateCacheInterface$settingsCache;
privateCacheInterface$responsesCache;
publicfunction__construct(CacheInterface$settingsCache, CacheInterface$responsesCache)
{
$this->settingsCache = $settingsCache;
$this->responsesCache = $responsesCache;
}
publicfunctionget(string$key) : ?string
{
$this->getStorage($key)->get($key);
}
publicfunctionset(string$key,string$data,?int$ttl = null) : void
{
$this->getStorage($key)->get($key, $data, $ttl);
}
privatefunctiongetStorage(string$key): CacheInterface
{
if (strpos($key, 'http.settings.') === 0) {
return$this->settingsCache;
}
if (strpos($key, 'http.response.') === 0) {
return$this->responsesCache;
}
thrownewInvalidArgumentException('can not define storage');
}
}

About

Cache interface for webclient/ext-cache

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages