View source
<?php
namespace Drupal\markdown\Util;
use Closure;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Cache\Store;
class LaravelCacheRepositoryAdapter implements Repository {
protected $store;
public function __construct(Store $store) {
$this->store = $store;
}
public function add($key, $value, $ttl = NULL) {
if (!$this
->has($key)) {
$this->store
->put($key, $value, $ttl);
}
}
public function clear() {
return $this->store
->flush();
}
public function decrement($key, $value = 1) {
return $this->store
->decrement($key, $value);
}
public function delete($key) {
return $this->store
->forget($key);
}
public function deleteMultiple($keys) {
foreach ($keys as $key) {
$this
->delete($key);
}
return TRUE;
}
public function forever($key, $value) {
return $this->store
->forever($key, $value);
}
public function forget($key) {
return $this->store
->forget($key);
}
public function get($key, $default = NULL) {
$value = $this->store
->get($key);
return isset($value) ? $value : $default;
}
public function getMultiple($keys, $default = NULL) {
$results = [];
foreach ($keys as $key) {
$results[] = $this
->get($key, $default);
}
return $results;
}
public function getStore() {
return $this->store;
}
public function has($key) {
return $this->store
->get($key) !== NULL;
}
public function increment($key, $value = 1) {
return $this->store
->increment($key, $value);
}
public function pull($key, $default = NULL) {
$value = $this
->get($key, $default);
$this
->delete($key);
return $value;
}
public function put($key, $value, $ttl = NULL) {
$this->store
->put($key, $value, $ttl);
}
public function remember($key, $ttl, Closure $callback) {
$value = $this
->get($key);
if (!isset($value)) {
$value = $callback();
$this
->put($key, $value, $ttl);
}
return $value;
}
public function rememberForever($key, Closure $callback) {
$value = $this
->get($key);
if (!isset($value)) {
$value = $callback();
$this
->forever($key, $value);
}
return $value;
}
public function sear($key, Closure $callback) {
$value = $this
->get($key);
if (!isset($value)) {
$value = $callback();
$this
->forever($key, $value);
}
return $value;
}
public function set($key, $value, $ttl = NULL) {
return $this->store
->put($key, $value, $ttl);
}
public function setMultiple($values, $ttl = NULL) {
return $this->store
->putMany((array) $values, $ttl);
}
}