LaravelCacheStoreAdapter.php in Markdown 8.2
File
src/Util/LaravelCacheStoreAdapter.php
View source
<?php
namespace Drupal\markdown\Util;
use Drupal\Core\Cache\CacheBackendInterface;
use Illuminate\Contracts\Cache\Store;
class LaravelCacheStoreAdapter implements Store {
protected $cache;
protected $prefix;
public function __construct(CacheBackendInterface $cacheBackend, $prefix = NULL) {
$this->cache = $cacheBackend;
$this->prefix = $prefix;
}
public function decrement($key, $value = 1) {
$key = $this
->prefixKey($key);
$value = $this->cache
->get($key) - $value;
$this->cache
->set($key, $value);
return $value;
}
public function flush() {
$this->cache
->deleteAll();
return TRUE;
}
public function forever($key, $value) {
$key = $this
->prefixKey($key);
$this->cache
->set($key, $value);
return TRUE;
}
public function forget($key) {
$key = $this
->prefixKey($key);
$this->cache
->delete($key);
return TRUE;
}
public function get($key) {
$key = $this
->prefixKey($key);
$cache = $this->cache
->get($key);
return isset($cache->data) ? $cache->data : NULL;
}
public function getPrefix() {
return $this->prefix;
}
public function increment($key, $value = 1) {
$key = $this
->prefixKey($key);
$value = $this->cache
->get($key) + $value;
$this->cache
->set($key, $value);
return $value;
}
public function many(array $keys) {
$result = [];
foreach ($keys as $key) {
$result[$this
->prefixKey($key)] = $this
->get($key);
}
return $result;
}
protected function prefixKey($key, $delimiter = '.') {
if ($this->prefix) {
return "{$this->prefix}{$delimiter}{$key}";
}
return $key;
}
public function put($key, $value, $seconds) {
$key = $this
->prefixKey($key);
$this->cache
->set($key, $value, REQUEST_TIME + $seconds);
return TRUE;
}
public function putMany(array $values, $seconds) {
foreach ($values as $key => $value) {
$this
->put($key, $values, $seconds);
}
return TRUE;
}
}