43 lines
835 B
PHP
43 lines
835 B
PHP
<?php
|
|
|
|
namespace App\Cache\Base;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
abstract class KeyBaseCache
|
|
{
|
|
protected string $prefix = 'Key:'; //缓存前缀
|
|
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
|
|
|
|
function getByKey($key): string|array|bool|null
|
|
{
|
|
return Cache::get($key);
|
|
}
|
|
|
|
function setKey($key, $value): bool
|
|
{
|
|
return Cache::put($this->getKey($key), $value);
|
|
}
|
|
|
|
function setKeyWithExp($key, $value, $exp = self::CACHE_TTL): bool
|
|
{
|
|
return Cache::put($this->getKey($key), $value, $exp);
|
|
}
|
|
|
|
function getPrefix(): string
|
|
{
|
|
return $this->prefix;
|
|
}
|
|
|
|
function getKey($key): string
|
|
{
|
|
return $this->getPrefix().$key;
|
|
}
|
|
|
|
function removeKey($key): bool
|
|
{
|
|
return Cache::forget($this->getKey($key));
|
|
}
|
|
|
|
}
|