Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.
/ cache Public archive

A flexible PSR-16 wrapper

Notifications You must be signed in to change notification settings

natsoman/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

A flexible PSR-16 wrapper.

Use

Prepare dependencies

\Psr\SimpleCache\CacheInterface

$service = new \RedisCluster(
    null,
    [
        'redis-cluster:7000',
        'redis-cluster:7001',
        'redis-cluster:7002',
        'redis-cluster:7003',
        'redis-cluster:7004',
        'redis-cluster:7005'
    ]
);

$adapter = new \Natso\Adapter\RedisAdapter($service);

\Natso\Serializer\SerializerInterface

$serializer = new \Natso\Serializer\NativeSerializer();

\Natso\KeyBuilder\KeyBuilderInterface


$map = [
    'staticKey'     => 'staticCacheKey',
    'uniqueKey'     => sprintf('uniqueCacheKey:%s', $_GET['id']),
    'closureKey'    => function () { return 'something that change in the runtime'; }
];

$keyBuilder = new \Natso\KeyBuilder\SimpleKeyBuilder($map);

\Natso\Compressor\CompressorInterface

$compressor = new \Natso\Compressor\ZlibCompressor();

Inject dependencies on the wrapper

$cache = new \Natso\Cache(
    $adapter,
    $serializer,
    $keyBuilder,
    $compressor,
    ['namespace' => 'Example', 'ttl' => 3600]
);

$key = '101';
$cache->set($key,101);
$cache->has($key);
$cache->get($key);
$cache->delete($key);

$keys = ['key0', 'key1', 'key2'];
$cache->setMultiple(['key0' => null, 'key1' => 101, 'key2' => new stdClass()]);
$cache->getMultiple($keys);
$cache->deleteMultiple($keys);

Memoization

In order to reduce the use of caching service, wrapper preserves an associative array which represents an extra caching layer.

About

A flexible PSR-16 wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages