You are here

DrupalFlysystemCache.php in Flysystem 7

Contains DrupalFlysystemCache.

Namespace

Drupal\flysystem

File

src/DrupalFlysystemCache.php
View source
<?php

/**
 * @file
 * Contains DrupalFlysystemCache.
 */
namespace Drupal\flysystem;

use League\Flysystem\Cached\Storage\AbstractCache;

/**
 * An adapter that allows Flysystem to use Drupal's cache system.
 */
class DrupalFlysystemCache extends AbstractCache {

  /**
   * The cache key.
   *
   * @var string
   */
  protected $key;

  /**
   * Constructs a DrupalFlysystemCache object.
   *
   * @param string $key
   *   The cache key to use.
   */
  public function __construct($key) {
    $this->key = $key;
  }

  /**
   * {@inheritdoc}
   */
  public function load() {
    if ($cache = cache_get($this->key)) {
      $this->cache = $cache->data[0];
      $this->complete = $cache->data[1];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function save() {
    $cleaned = $this
      ->cleanContents($this->cache);
    cache_set($this->key, array(
      $cleaned,
      $this->complete,
    ));
  }

}

Classes

Namesort descending Description
DrupalFlysystemCache An adapter that allows Flysystem to use Drupal's cache system.