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

Commit098a6ea

Browse files
André Rnicolas-grekas
André R
authored andcommitted
[Cache] Add optimized FileSystem & Redis TagAware Adapters
Reduces cache lookups by 50% by changing logic of how tag information isstored to avoid having to look it up on getItem(s) calls.For Filesystem symlinks are used, for Redis "Set" datatype is used.
1 parent7e56ef1 commit098a6ea

21 files changed

+1266
-257
lines changed

‎phpunit.xml.dist‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@
7171
<elementkey="1"><string>Doctrine\Common\Cache</string></element>
7272
<elementkey="2"><string>Symfony\Component\Cache</string></element>
7373
<elementkey="3"><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
74-
<elementkey="4"><string>Symfony\Component\Cache\Traits</string></element>
75-
<elementkey="5"><string>Symfony\Component\Console</string></element>
76-
<elementkey="6"><string>Symfony\Component\HttpFoundation</string></element>
74+
<elementkey="4"><string>Symfony\Component\Cache\Tests\Traits</string></element>
75+
<elementkey="5"><string>Symfony\Component\Cache\Traits</string></element>
76+
<elementkey="6"><string>Symfony\Component\Console</string></element>
77+
<elementkey="7"><string>Symfony\Component\HttpFoundation</string></element>
7778
</array>
7879
</element>
7980
</array>

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php‎

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
namespaceSymfony\Component\Cache\Adapter;
1313

14-
usePsr\Cache\CacheItemInterface;
1514
usePsr\Log\LoggerAwareInterface;
1615
usePsr\Log\LoggerInterface;
1716
usePsr\Log\NullLogger;
1817
useSymfony\Component\Cache\CacheItem;
1918
useSymfony\Component\Cache\Exception\InvalidArgumentException;
2019
useSymfony\Component\Cache\ResettableInterface;
21-
useSymfony\Component\Cache\Traits\AbstractTrait;
20+
useSymfony\Component\Cache\Traits\AbstractAdapterTrait;
2221
useSymfony\Component\Cache\Traits\ContractsTrait;
2322
useSymfony\Contracts\Cache\CacheInterface;
2423

@@ -27,15 +26,12 @@
2726
*/
2827
abstractclass AbstractAdapterimplements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
2928
{
30-
useAbstractTrait;
29+
useAbstractAdapterTrait;
3130
use ContractsTrait;
3231

3332
privatestatic$apcuSupported;
3433
privatestatic$phpFilesSupported;
3534

36-
private$createCacheItem;
37-
private$mergeByLifetime;
38-
3935
protectedfunction__construct(string$namespace ='',int$defaultLifetime =0)
4036
{
4137
$this->namespace ='' ===$namespace ?'' : CacheItem::validateKey($namespace).':';
@@ -142,81 +138,6 @@ public static function createConnection($dsn, array $options = [])
142138
thrownewInvalidArgumentException(sprintf('Unsupported DSN: %s.',$dsn));
143139
}
144140

145-
/**
146-
* {@inheritdoc}
147-
*/
148-
publicfunctiongetItem($key)
149-
{
150-
if ($this->deferred) {
151-
$this->commit();
152-
}
153-
$id =$this->getId($key);
154-
155-
$f =$this->createCacheItem;
156-
$isHit =false;
157-
$value =null;
158-
159-
try {
160-
foreach ($this->doFetch([$id])as$value) {
161-
$isHit =true;
162-
}
163-
}catch (\Exception$e) {
164-
CacheItem::log($this->logger,'Failed to fetch key "{key}"', ['key' =>$key,'exception' =>$e]);
165-
}
166-
167-
return$f($key,$value,$isHit);
168-
}
169-
170-
/**
171-
* {@inheritdoc}
172-
*/
173-
publicfunctiongetItems(array$keys = [])
174-
{
175-
if ($this->deferred) {
176-
$this->commit();
177-
}
178-
$ids = [];
179-
180-
foreach ($keysas$key) {
181-
$ids[] =$this->getId($key);
182-
}
183-
try {
184-
$items =$this->doFetch($ids);
185-
}catch (\Exception$e) {
186-
CacheItem::log($this->logger,'Failed to fetch requested items', ['keys' =>$keys,'exception' =>$e]);
187-
$items = [];
188-
}
189-
$ids =array_combine($ids,$keys);
190-
191-
return$this->generateItems($items,$ids);
192-
}
193-
194-
/**
195-
* {@inheritdoc}
196-
*/
197-
publicfunctionsave(CacheItemInterface$item)
198-
{
199-
if (!$iteminstanceof CacheItem) {
200-
returnfalse;
201-
}
202-
$this->deferred[$item->getKey()] =$item;
203-
204-
return$this->commit();
205-
}
206-
207-
/**
208-
* {@inheritdoc}
209-
*/
210-
publicfunctionsaveDeferred(CacheItemInterface$item)
211-
{
212-
if (!$iteminstanceof CacheItem) {
213-
returnfalse;
214-
}
215-
$this->deferred[$item->getKey()] =$item;
216-
217-
returntrue;
218-
}
219-
220141
/**
221142
* {@inheritdoc}
222143
*/
@@ -271,33 +192,4 @@ public function commit()
271192

272193
return$ok;
273194
}
274-
275-
publicfunction__destruct()
276-
{
277-
if ($this->deferred) {
278-
$this->commit();
279-
}
280-
}
281-
282-
privatefunctiongenerateItems($items, &$keys)
283-
{
284-
$f =$this->createCacheItem;
285-
286-
try {
287-
foreach ($itemsas$id =>$value) {
288-
if (!isset($keys[$id])) {
289-
$id =key($keys);
290-
}
291-
$key =$keys[$id];
292-
unset($keys[$id]);
293-
yield$key =>$f($key,$value,true);
294-
}
295-
}catch (\Exception$e) {
296-
CacheItem::log($this->logger,'Failed to fetch requested items', ['keys' =>array_values($keys),'exception' =>$e]);
297-
}
298-
299-
foreach ($keysas$key) {
300-
yield$key =>$f($key,null,false);
301-
}
302-
}
303195
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp