Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Apcu cache driver #11

Merged
merged 6 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions src/Moust/Silex/Cache/ApcuCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* This file is part of CacheServiceProvider.
*
* (c) Quentin Aupetit <qaupetit@gmail.com>
*
* 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);
}
}
1 change: 1 addition & 0 deletions src/Moust/Silex/Provider/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
38 changes: 38 additions & 0 deletions tests/Cache/ApcuCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of CacheServiceProvider.
*
* (c) Quentin Aupetit <qaupetit@gmail.com>
*
* 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");
}
}
2 changes: 2 additions & 0 deletions tests/travis/php.ini
Original file line number Diff line number Diff line change
@@ -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