mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 05:53:13 +00:00

- Squashed Pull request #1730 - Squashed Pull request #1741 - Squashed Pull request #1742 - Squash merge branch 4.0 - Squashed Pull request #1744 - Squashed Pull request #1746 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed Pull request #1758 - Avoid using imagine/imagine alias as it is causing install issues - Squashed merge branch 4.0 - Squashed Pull request #1763 - Squashed merge branch 4.0 - Squash of 6 commits - Squashed merge branch 4.0 - This is a combination of 2 commits. - Squashed Pull request #1775 - Squashed Pull request #1777 - Squashed Pull request #1779 - Squashed Pull request #1780 - Squashed Pull request #1782 - Adds a Pull request template - Squased Pull request #1783 - Squash Pull request #1786 - Squashed Pull request #1796 - Squashed merge branch 4.0 - Squash Pull request #1791 - Squashed merge branch 4.0 - Squashed Pull request #1808 - Squashed Pull request #1811 - Squashed Pull request #1809
89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Cache;
|
|
|
|
use Doctrine\Common\Cache\Cache as DoctrineCache;
|
|
use Doctrine\Common\Cache\MultiGetCache;
|
|
use Doctrine\Common\Cache\MultiPutCache;
|
|
|
|
class MultiAdapter implements DoctrineCache, MultiGetCache, MultiPutCache
|
|
{
|
|
/**
|
|
* @var DoctrineCache
|
|
*/
|
|
private $cache;
|
|
|
|
public function __construct(DoctrineCache $cache)
|
|
{
|
|
$this->cache = $cache;
|
|
}
|
|
|
|
public function fetch($id)
|
|
{
|
|
return $this->cache->fetch($id);
|
|
}
|
|
|
|
public function contains($id)
|
|
{
|
|
return $this->cache->contains($id);
|
|
}
|
|
|
|
public function save($id, $data, $lifeTime = 0)
|
|
{
|
|
return $this->cache->save($id, $data, $lifeTime);
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
return $this->cache->delete($id);
|
|
}
|
|
|
|
public function getStats()
|
|
{
|
|
return $this->cache->getStats();
|
|
}
|
|
|
|
public function fetchMultiple(array $keys)
|
|
{
|
|
if ($this->cache instanceof MultiGetCache) {
|
|
return $this->cache->fetchMultiple($keys);
|
|
}
|
|
|
|
// Pass data by reference to avoid copies of whole array on key add.
|
|
$data = array_reduce($keys, function (array &$data, $key) {
|
|
$value = $this->fetch($key);
|
|
|
|
if (false !== $value || true === $this->contains($key)) {
|
|
$data[$key] = $value;
|
|
}
|
|
|
|
return $data;
|
|
}, []);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function saveMultiple(array $keysAndValues, $lifetime = 0)
|
|
{
|
|
if ($this->cache instanceof MultiPutCache) {
|
|
return $this->cache->saveMultiple($keysAndValues, $lifetime);
|
|
}
|
|
|
|
foreach ($keysAndValues as $key => $value) {
|
|
if (!$this->cache->save($key, $value, $lifetime)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|