You are here

class AwsCacheAdapter in Flysystem - S3 8

Same name and namespace in other branches
  1. 2.0.x src/AwsCacheAdapter.php \Drupal\flysystem_s3\AwsCacheAdapter

A Drupal cache adapter for use with the AWS PHP SDK.

Hierarchy

Expanded class hierarchy of AwsCacheAdapter

2 files declare their use of AwsCacheAdapter
AwsCacheAdapterTest.php in tests/src/Unit/AwsCacheAdapterTest.php
S3.php in src/Flysystem/S3.php

File

src/AwsCacheAdapter.php, line 11

Namespace

Drupal\flysystem_s3
View source
class AwsCacheAdapter implements CacheInterface {

  /**
   * The cache backend.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  private $cache;

  /**
   * The cache prefix.
   *
   * @var string
   */
  private $prefix;

  /**
   * Constructs an AwsCacheAdapter object.
   *
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
   *   The Drupal cache backend.
   * @param string $prefix
   *   (Optional) The prefix to use for cache items. Defaults to an empty
   *   string.
   */
  public function __construct(CacheBackendInterface $cache, $prefix = '') {
    $this->cache = $cache;
    $this->prefix = $prefix;
  }

  /**
   * {@inheritdoc}
   */
  public function get($key) {
    if ($item = $this->cache
      ->get($this->prefix . $key)) {
      return $item->data;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function set($key, $value, $ttl = 0) {
    $ttl = (int) $ttl;
    $ttl = $ttl === 0 ? CacheBackendInterface::CACHE_PERMANENT : time() + $ttl;
    $this->cache
      ->set($this->prefix . $key, $value, $ttl);
  }

  /**
   * {@inheritdoc}
   */
  public function remove($key) {
    $this->cache
      ->delete($this->prefix . $key);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AwsCacheAdapter::$cache private property The cache backend.
AwsCacheAdapter::$prefix private property The cache prefix.
AwsCacheAdapter::get public function
AwsCacheAdapter::remove public function
AwsCacheAdapter::set public function
AwsCacheAdapter::__construct public function Constructs an AwsCacheAdapter object.