vendor/symfony/cache/Adapter/NullAdapter.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Cache\Adapter;
  11. use Psr\Cache\CacheItemInterface;
  12. use Symfony\Component\Cache\CacheItem;
  13. use Symfony\Contracts\Cache\CacheInterface;
  14. /**
  15.  * @author Titouan Galopin <galopintitouan@gmail.com>
  16.  */
  17. class NullAdapter implements AdapterInterfaceCacheInterface
  18. {
  19.     private static $createCacheItem;
  20.     public function __construct()
  21.     {
  22.         self::$createCacheItem ?? self::$createCacheItem = \Closure::bind(
  23.             static function ($key) {
  24.                 $item = new CacheItem();
  25.                 $item->key $key;
  26.                 $item->isHit false;
  27.                 return $item;
  28.             },
  29.             null,
  30.             CacheItem::class
  31.         );
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function get(string $key, callable $callbackfloat $beta null, array &$metadata null)
  37.     {
  38.         $save true;
  39.         return $callback((self::$createCacheItem)($key), $save);
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function getItem($key)
  45.     {
  46.         return (self::$createCacheItem)($key);
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function getItems(array $keys = [])
  52.     {
  53.         return $this->generateItems($keys);
  54.     }
  55.     /**
  56.      * {@inheritdoc}
  57.      *
  58.      * @return bool
  59.      */
  60.     public function hasItem($key)
  61.     {
  62.         return false;
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      *
  67.      * @return bool
  68.      */
  69.     public function clear(string $prefix '')
  70.     {
  71.         return true;
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      *
  76.      * @return bool
  77.      */
  78.     public function deleteItem($key)
  79.     {
  80.         return true;
  81.     }
  82.     /**
  83.      * {@inheritdoc}
  84.      *
  85.      * @return bool
  86.      */
  87.     public function deleteItems(array $keys)
  88.     {
  89.         return true;
  90.     }
  91.     /**
  92.      * {@inheritdoc}
  93.      *
  94.      * @return bool
  95.      */
  96.     public function save(CacheItemInterface $item)
  97.     {
  98.         return true;
  99.     }
  100.     /**
  101.      * {@inheritdoc}
  102.      *
  103.      * @return bool
  104.      */
  105.     public function saveDeferred(CacheItemInterface $item)
  106.     {
  107.         return true;
  108.     }
  109.     /**
  110.      * {@inheritdoc}
  111.      *
  112.      * @return bool
  113.      */
  114.     public function commit()
  115.     {
  116.         return true;
  117.     }
  118.     /**
  119.      * {@inheritdoc}
  120.      */
  121.     public function delete(string $key): bool
  122.     {
  123.         return $this->deleteItem($key);
  124.     }
  125.     private function generateItems(array $keys): \Generator
  126.     {
  127.         $f self::$createCacheItem;
  128.         foreach ($keys as $key) {
  129.             yield $key => $f($key);
  130.         }
  131.     }
  132. }