Skip to content

Allows to store data with caching engines (Memcache, file system, etc).

License

Notifications You must be signed in to change notification settings

jmfeurprier/perf-caching

Repository files navigation

perf caching

Allows caching of data (with Memcached, file-system, etc).

Usage

Initialization

<?php

use perf\Caching\CacheClient;
use perf\Caching\Storage\FileSystemCachingStorage;
use perf\Caching\Storage\MemcachedCachingStorage;
use perf\Caching\Storage\NullCachingStorage;
use perf\Caching\Storage\VolatileCachingStorage;

// Memcached
$storage = MemcachedCachingStorage::createFromCredentials('1.2.3.4', 123);
$cache   = CacheClient::createWithStorage($storage);

// Volatile storage
$storage = new VolatileCachingStorage();
$cache   = CacheClient::createWithStorage($storage);

// File-system storage
$storage = new FileSystemCachingStorage('/tmp/cache');
$cache   = CacheClient::createWithStorage($storage);

// Null storage (caches nothing)
$storage = new NullCachingStorage();
$cache   = CacheClient::createWithStorage($storage);

Storing and retrieving data

<?php

$objectToStore = new \stdClass();
$objectToStore->bar = 'baz';

$cache->store('foo', $objectToStore);

// ...

$object = $cache->tryFetch('foo');

About

Allows to store data with caching engines (Memcache, file system, etc).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages