Skip to content

Commit 5095a3b

Browse files
committed
Merge pull request #1 from nicholasruunu/master
Memcache adapter
2 parents e84224d + 4e52923 commit 5095a3b

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

.travis-php.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extension = memcache.so

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
language: php
22
php:
3-
- 7.0
4-
- 5.6
5-
- 5.5
6-
- hhvm
3+
- "5.6"
4+
- "5.5"
5+
- "hhvm"
76

87
sudo: false
98

9+
services:
10+
- memcached
11+
1012
matrix:
1113
fast_finish: true
1214

1315
before_install:
14-
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' ]]; then phpenv config-rm xdebug.ini; fi;
15-
- pip install --user codecov
16+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-rm xdebug.ini; fi;'
17+
- pip install --user codecov
1618

1719
before_script:
20+
# Need to activate memchache extension explictly to work with all versions.
21+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-add .travis-php.ini; fi;'
1822
- travis_retry composer self-update
1923
- travis_retry composer install --prefer-source --no-interaction
2024

2125
script:
22-
- php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-clover=coverage.xml
26+
- php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-clover=coverage.xml
2327

2428
after_success:
25-
- codecov
29+
- codecov

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
],
2828
"require":
2929
{
30-
"php": "^5.5|7.0",
30+
"php": "^5.5",
31+
"ext-memcache": "*",
3132
"psr/cache": "1.0.0",
3233
"cache/adapter-common": "^0.1",
3334
"cache/taggable-cache": "^0.2"
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,40 @@
1212
namespace Cache\Adapter\Memcache;
1313

1414
use Cache\Adapter\Common\AbstractCachePool;
15+
use Memcache;
1516
use Psr\Cache\CacheItemInterface;
1617

17-
/**
18-
*
19-
*/
2018
class MemcacheCachePool extends AbstractCachePool
2119
{
20+
/**
21+
* @var Memcache
22+
*/
23+
private $cache;
24+
25+
public function __construct(Memcache $cache)
26+
{
27+
$this->cache = $cache;
28+
}
29+
2230
protected function fetchObjectFromCache($key)
2331
{
24-
return false;
32+
return $this->cache->get($key);
2533
}
2634

2735
protected function clearAllObjectsFromCache()
2836
{
29-
return true;
37+
return $this->cache->flush();
3038
}
3139

3240
protected function clearOneObjectFromCache($key)
3341
{
42+
$this->cache->delete($key);
43+
3444
return true;
3545
}
3646

3747
protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
3848
{
39-
return true;
49+
return $this->cache->set($key, $item, 0, $ttl ?: 0);
4050
}
4151
}

tests/IntegrationPoolTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313

1414
use Cache\Adapter\Memcache\MemcacheCachePool;
1515
use Cache\IntegrationTests\CachePoolTest;
16+
use Memcache;
1617

1718
class IntegrationPoolTest extends CachePoolTest
1819
{
20+
private $client;
21+
1922
public function createCachePool()
2023
{
21-
return new MemcacheCachePool();
24+
return new MemcacheCachePool($this->getClient());
25+
}
26+
27+
private function getClient()
28+
{
29+
if ($this->client === null) {
30+
$this->client = new Memcache;
31+
$this->client->connect('localhost', 11211);
32+
}
33+
34+
return $this->client;
2235
}
2336
}

tests/IntegrationTagTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313

1414
use Cache\Adapter\Memcache\MemcacheCachePool;
1515
use Cache\IntegrationTests\TaggableCachePoolTest;
16+
use Memcache;
1617

1718
class IntegrationTagTest extends TaggableCachePoolTest
1819
{
20+
private $client;
21+
1922
public function createCachePool()
2023
{
21-
return new MemcacheCachePool();
24+
return new MemcacheCachePool($this->getClient());
25+
}
26+
27+
private function getClient()
28+
{
29+
if ($this->client === null) {
30+
$this->client = new Memcache;
31+
$this->client->connect('localhost', 11211);
32+
}
33+
34+
return $this->client;
2235
}
2336
}

0 commit comments

Comments
 (0)