dev-master
9999999-devCache library that extends Doctrine\Cache capabilities
MIT
The Requires
- php >=5.3.3
- doctrine/cache ~1
The Development Requires
by OpenClassrooms
by Romain Kuzniak
cache
Wallogit.com
2017 © Pedro Peláez
Cache library that extends Doctrine\Cache capabilities
Cache adds features to Doctrine Cache implementation - Default lifetime - Fetch with a namespace - Save with a namespace - Cache invalidation through namespace strategy - CacheProvider Builder, (*2)
The easiest way to install Cache is via composer., (*3)
Create the following composer.json file and run the php composer.phar install command to install it., (*4)
{
"require": {
"openclassrooms/cache": "*"
}
}
```php <?php require 'vendor/autoload.php';, (*5)
use OpenClassrooms\Cache\Cache\Cache;, (*6)
//do things, (*7)
<a name="install-nocomposer"/> ## Usage ### Instantiation OC Cache needs a Doctrine CacheProvider to be instantiate. ```php $cacheProvider = new ArrayCache(); $cache = new Cache($cacheProvider);
A Cache builder can be used., (*8)
// Default builder, build a cache using ArrayCache Provider
$cache = new CacheBuilderImpl()->build();
// Using a CacheProvider
$cache = new CacheBuilderImpl()
->withCacheProvider($redisCache)
->build();
// Optional default lifetime
$cache = new CacheBuilderImpl()
->withCacheProvider($redisCache)
->withDefaultLifetime(300)
->build();
$cache->setDefaultLifetime(300); $cache->save($id, $data);
$data = $cache->fetchWithNamespace($id, $namespaceId);
// Namespace and life time can be null $data = $cache->saveWithNamespace($id, $data, $namespaceId, $lifeTime);
$cache->invalidate($namespaceId);
The library provides a CacheProvider Builder, (*9)
// Memcache
$cacheProvider = new CacheProviderBuilderImpl()
->create(CacheProviderType::MEMCACHE)
->withHost('127.0.0.1')
->withPort(11211) // Default 11211
->withTimeout(1) // Default 1
->build();
// Memcached
$cacheProvider = new CacheProviderBuilderImpl()
->create(CacheProviderType::MEMCACHED)
->withHost('127.0.0.1')
->withPort(11211) // Default 11211
->build();
// Redis
$cacheProvider = new CacheProviderBuilderImpl()
->create(CacheProviderType::REDIS)
->withHost('127.0.0.1')
->withPort(6379) // Default 6379
->withTimeout(0.0) // Default 0.0
->build();
// Array
$cacheProvider = new CacheProviderBuilderImpl()
->create(CacheProviderType::ARRAY_CACHE)
->build();
Cache library that extends Doctrine\Cache capabilities
MIT
cache