<?php<liu21st@gmail.com>declare (strict_types = 1);
namespace think;
use Psr\SimpleCache\CacheInterface;
use think\cache\Driver;
use think\cache\TagSet;
use think\exception\InvalidArgumentException;
use think\helper\Arr;
class Cache extends Manager implements CacheInterface
{
protected $namespace = '\\think\\cache\\driver\\';
public function getDefaultDriver()
{
return $this->getConfig('default');
}
public function getConfig(string $name = null, $default = null)
{
if (!is_null($name)) {
return $this->app->config->get('cache.' . $name, $default);
}
return $this->app->config->get('cache');
}
public function getStoreConfig(string $store, string $name = null, $default = null)
{
if ($config = $this->getConfig("stores.{$store}")) {
return Arr::get($config, $name, $default);
}
throw new \InvalidArgumentException("Store [$store] not found.");
}
protected function resolveType(string $name)
{
return $this->getStoreConfig($name, 'type', 'file');
}
protected function resolveConfig(string $name)
{
return $this->getStoreConfig($name);
}
public function store(string $name = null)
{
return $this->driver($name);
}
public function clear(): bool
{
return $this->store()->clear();
}
public function get($key, $default = null)
{
return $this->store()->get($key, $default);
}
public function set($key, $value, $ttl = null): bool
{
return $this->store()->set($key, $value, $ttl);
}
public function delete($key): bool
{
return $this->store()->delete($key);
}
public function getMultiple($keys, $default = null): iterable
{
return $this->store()->getMultiple($keys, $default);
}
public function setMultiple($values, $ttl = null): bool
{
return $this->store()->setMultiple($values, $ttl);
}
public function deleteMultiple($keys): bool
{
return $this->store()->deleteMultiple($keys);
}
public function has($key): bool
{
return $this->store()->has($key);
}
public function tag($name): TagSet
{
return $this->store()->tag($name);
}
}