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

Appearance settings

[Cache] Add optimized FileSystem & Redis TagAware Adapters #30370

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

Merged
merged 1 commit into from
Apr 24, 2019
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
7 changes: 4 additions & 3 deletions 7 phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@
<element key="1"><string>Doctrine\Common\Cache</string></element>
<element key="2"><string>Symfony\Component\Cache</string></element>
<element key="3"><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
<element key="4"><string>Symfony\Component\Cache\Traits</string></element>
<element key="5"><string>Symfony\Component\Console</string></element>
<element key="6"><string>Symfony\Component\HttpFoundation</string></element>
<element key="4"><string>Symfony\Component\Cache\Tests\Traits</string></element>
<element key="5"><string>Symfony\Component\Cache\Traits</string></element>
<element key="6"><string>Symfony\Component\Console</string></element>
<element key="7"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</element>
</array>
Expand Down
112 changes: 2 additions & 110 deletions 112 src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

namespace Symfony\Component\Cache\Adapter;

use Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\AbstractTrait;
use Symfony\Component\Cache\Traits\AbstractAdapterTrait;
use Symfony\Component\Cache\Traits\ContractsTrait;
use Symfony\Contracts\Cache\CacheInterface;

Expand All @@ -27,15 +26,12 @@
*/
abstract class AbstractAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
{
use AbstractTrait;
use AbstractAdapterTrait;
use ContractsTrait;

private static $apcuSupported;
private static $phpFilesSupported;

private $createCacheItem;
private $mergeByLifetime;

protected function __construct(string $namespace = '', int $defaultLifetime = 0)
{
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).':';
Expand Down Expand Up @@ -142,81 +138,6 @@ public static function createConnection($dsn, array $options = [])
throw new InvalidArgumentException(sprintf('Unsupported DSN: %s.', $dsn));
}

/**
* {@inheritdoc}
*/
public function getItem($key)
{
if ($this->deferred) {
$this->commit();
}
$id = $this->getId($key);

$f = $this->createCacheItem;
$isHit = false;
$value = null;

try {
foreach ($this->doFetch([$id]) as $value) {
$isHit = true;
}
} catch (\Exception $e) {
CacheItem::log($this->logger, 'Failed to fetch key "{key}"', ['key' => $key, 'exception' => $e]);
}

return $f($key, $value, $isHit);
}

/**
* {@inheritdoc}
*/
public function getItems(array $keys = [])
{
if ($this->deferred) {
$this->commit();
}
$ids = [];

foreach ($keys as $key) {
$ids[] = $this->getId($key);
}
try {
$items = $this->doFetch($ids);
} catch (\Exception $e) {
CacheItem::log($this->logger, 'Failed to fetch requested items', ['keys' => $keys, 'exception' => $e]);
$items = [];
}
$ids = array_combine($ids, $keys);

return $this->generateItems($items, $ids);
}

/**
* {@inheritdoc}
*/
public function save(CacheItemInterface $item)
{
if (!$item instanceof CacheItem) {
return false;
}
$this->deferred[$item->getKey()] = $item;

return $this->commit();
}

/**
* {@inheritdoc}
*/
public function saveDeferred(CacheItemInterface $item)
{
if (!$item instanceof CacheItem) {
return false;
}
$this->deferred[$item->getKey()] = $item;

return true;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -271,33 +192,4 @@ public function commit()

return $ok;
}

public function __destruct()
{
if ($this->deferred) {
$this->commit();
}
}

private function generateItems($items, &$keys)
{
$f = $this->createCacheItem;

try {
foreach ($items as $id => $value) {
if (!isset($keys[$id])) {
$id = key($keys);
}
$key = $keys[$id];
unset($keys[$id]);
yield $key => $f($key, $value, true);
}
} catch (\Exception $e) {
CacheItem::log($this->logger, 'Failed to fetch requested items', ['keys' => array_values($keys), 'exception' => $e]);
}

foreach ($keys as $key) {
yield $key => $f($key, null, false);
}
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.