Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94e8e88

Browse files
committed
memcached cache pool adapter
1 parentd6e8937 commit94e8e88

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Cache\Adapter;
13+
14+
/**
15+
* @author Rob Frawley 2nd <rmf@src.run>
16+
*/
17+
class MemcachedAdapterextends AbstractAdapter
18+
{
19+
private$client;
20+
21+
publicstaticfunctionisSupported()
22+
{
23+
returnextension_loaded('memcached') &&version_compare(phpversion('memcached'),'2.2.0','>=');
24+
}
25+
26+
publicfunction__construct(\Memcached$client,$namespace ='',$defaultLifetime =0)
27+
{
28+
parent::__construct($namespace,$defaultLifetime);
29+
$this->client =$client;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protectedfunctiondoSave(array$values,$lifetime)
36+
{
37+
return$this->client->setMulti($values,$lifetime)
38+
&&$this->client->getResultCode() === \Memcached::RES_SUCCESS;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protectedfunctiondoFetch(array$ids)
45+
{
46+
return$this->client->getMulti($ids);
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
protectedfunctiondoHave($id)
53+
{
54+
return$this->client->get($id) !==false
55+
||$this->client->getResultCode() === \Memcached::RES_SUCCESS;
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protectedfunctiondoDelete(array$ids)
62+
{
63+
$toDelete =count($ids);
64+
foreach ((array)$this->client->deleteMulti($ids)as$result) {
65+
if (true ===$result || \Memcached::RES_NOTFOUND ===$result) {
66+
--$toDelete;
67+
}
68+
}
69+
70+
return0 ===$toDelete;
71+
}
72+
73+
/**
74+
* {@inheritdoc}
75+
*/
76+
protectedfunctiondoClear($namespace)
77+
{
78+
return$this->client->flush();
79+
}
80+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Cache\Tests\Adapter;
13+
14+
useSymfony\Component\Cache\Adapter\MemcachedAdapter;
15+
16+
class MemcachedAdapterTestextends AdapterTestCase
17+
{
18+
protected$skippedTests =array(
19+
'testExpiration' =>'Testing expiration slows down the test suite',
20+
'testHasItemReturnsFalseWhenDeferredItemIsExpired' =>'Testing expiration slows down the test suite',
21+
'testDefaultLifeTime' =>'Testing expiration slows down the test suite',
22+
);
23+
24+
privatestatic$client;
25+
26+
publicstaticfunctionsetupBeforeClass()
27+
{
28+
if (!MemcachedAdapter::isSupported()) {
29+
self::markTestSkipped('Extension memcached >=2.2.0 required.');
30+
}
31+
32+
self::$client =new \Memcached();
33+
self::$client->addServers(array(array(
34+
getenv('MEMCACHED_HOST') ?:'127.0.0.1',
35+
getenv('MEMCACHED_PORT') ?:11211,
36+
)));
37+
38+
parent::setupBeforeClass();
39+
}
40+
41+
publicfunctioncreateCachePool($defaultLifetime =0)
42+
{
43+
returnnewMemcachedAdapter(self::$client,str_replace('\\','.',__CLASS__),$defaultLifetime);
44+
}
45+
46+
publicfunctiontestIsSupported()
47+
{
48+
$this->assertTrue(MemcachedAdapter::isSupported());
49+
}
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp