Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  
   3  namespace Kevinrob\GuzzleCache\Storage;
   4  
   5  use Kevinrob\GuzzleCache\CacheEntry;
   6  use Psr\SimpleCache\CacheInterface;
   7  
   8  class Psr16CacheStorage implements CacheStorageInterface
   9  {
  10      /**
  11       * @var CacheInterface
  12       */
  13      private $cache;
  14  
  15      public function __construct(CacheInterface $cache)
  16      {
  17          $this->cache = $cache;
  18      }
  19  
  20      /**
  21       * {@inheritdoc}
  22       */
  23      public function fetch($key)
  24      {
  25          $data = $this->cache->get($key);
  26          if ($data instanceof CacheEntry) {
  27              return $data;
  28          }
  29  
  30          return null;
  31      }
  32  
  33      /**
  34       * {@inheritdoc}
  35       */
  36      public function save($key, CacheEntry $data)
  37      {
  38          $ttl = $data->getTTL();
  39          if ($ttl === 0) {
  40          return $this->cache->set($key, $data);
  41          }
  42          return $this->cache->set($key, $data, $data->getTTL());
  43      }
  44  
  45      /**
  46       * {@inheritdoc}
  47       */
  48      public function delete($key)
  49      {
  50          return $this->cache->delete($key);
  51      }
  52  }