diff --git a/README.md b/README.md index b4cce7c..1b394e4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ To enable it, add this dependency to your ``composer.json`` file: ## Parameters - **cache.options**: Array of cache options. - - **driver**: The cache driver to use. Can be any of: `apc`, `array`, `file`, `memcache`, `memcached`, `xcache`, `redis`, `wincache`. + - **driver**: The cache driver to use. Can be any of: `apc`,`apcu`, `array`, `file`, `memcache`, `memcached`, `xcache`, `redis`, `wincache`. - **cache_dir**: Only relevant for `file` cache driver, specifies the path to the cache directory - **memcache**: Only relevant for `memcache` cache driver, provide the Memcache instance to use. If not defined, a default Memcache object will be instanciated. See the Memcache documentation for additional informations : [PHP: Memcache - Manual](http://www.php.net/manual/en/book.memcache.php) - **memcached**: Only relevant for `memcached` cache driver, provide the Memcached instance to use. If not defined, a default Memcached object will be instanciated. See the Memcached documentation for additional informations : [PHP: Memcached - Manual](http://www.php.net/manual/en/book.memcached.php) diff --git a/src/Moust/Silex/Cache/ApcuCache.php b/src/Moust/Silex/Cache/ApcuCache.php new file mode 100644 index 0000000..2773be1 --- /dev/null +++ b/src/Moust/Silex/Cache/ApcuCache.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Moust\Silex\Cache; + +class ApcuCache extends AbstractCache +{ + /** + * {@inheritdoc} + */ + static function isSupported() + { + return extension_loaded('apcu'); + } + + /** + * {@inheritdoc} + */ + public function clear() + { + return apcu_clear_cache(); + } + + /** + * {@inheritdoc} + */ + public function delete($key) + { + return apcu_delete($key); + } + + /** + * {@inheritdoc} + */ + public function exists($key) + { + return apcu_exists($key); + } + + /** + * {@inheritdoc} + */ + public function fetch($key) + { + return apcu_fetch($key); + } + + /** + * {@inheritdoc} + */ + public function store($key, $var = null, $ttl = 0) + { + return apcu_store($key, $var, (int) $ttl); + } +} diff --git a/src/Moust/Silex/Provider/CacheServiceProvider.php b/src/Moust/Silex/Provider/CacheServiceProvider.php index 3d5bad4..ca0130e 100644 --- a/src/Moust/Silex/Provider/CacheServiceProvider.php +++ b/src/Moust/Silex/Provider/CacheServiceProvider.php @@ -28,6 +28,7 @@ public function register(Container $app) $app['cache.drivers'] = function () { return array( 'apc' => '\\Moust\\Silex\\Cache\\ApcCache', + 'apcu' => '\\Moust\\Silex\\Cache\\ApcuCache', 'array' => '\\Moust\\Silex\\Cache\\ArrayCache', 'file' => '\\Moust\\Silex\\Cache\\FileCache', 'memcache' => '\\Moust\\Silex\\Cache\\MemcacheCache', diff --git a/tests/Cache/ApcuCacheTest.php b/tests/Cache/ApcuCacheTest.php new file mode 100644 index 0000000..d941958 --- /dev/null +++ b/tests/Cache/ApcuCacheTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Moust\Silex\Tests\Cache; + +use Moust\Silex\Cache\ApcuCache; + +class ApcuCacheTest extends AbstractCacheTest +{ + protected function setUp() + { + if (!extension_loaded('apcu')) { + $this->markTestSkipped('L\'extension APCu n\'est pas disponible.'); + } + } + + public function instanciateCache() + { + $cache = new ApcuCache(); + + $this->assertInstanceOf('Moust\Silex\Cache\ApcuCache', $cache); + + return $cache; + } + + public function testCacheTtl() + { + $this->markTestSkipped("APCu will only expunged its cache on the next request"); + } +} diff --git a/tests/travis/php.ini b/tests/travis/php.ini index 7fe58bf..23f4a98 100644 --- a/tests/travis/php.ini +++ b/tests/travis/php.ini @@ -1,7 +1,9 @@ extension=apc.so +extension=apcu.so extension=memcache.so extension=memcached.so extension=redis.so + apc.enabled=1 apc.enable_cli=1