From f2d8ac626ecd623a9351a8933d0055d54cfecb1d Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Thu, 18 Jul 2024 14:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9cache=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/library/cache/driver/File.php | 23 +++++++++++------------ framework/library/cache/driver/Redis.php | 8 ++++---- framework/library/cache/ifs/CacheIfs.php | 6 +++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/framework/library/cache/driver/File.php b/framework/library/cache/driver/File.php index 946a2a3..a0112f6 100644 --- a/framework/library/cache/driver/File.php +++ b/framework/library/cache/driver/File.php @@ -17,7 +17,6 @@ class File implements CacheIfs /** * 当前实例 - * @var */ private static $instance; @@ -29,16 +28,16 @@ class File implements CacheIfs /** * 默认缓存位置 - * @var null|string + * @var string */ private $dir = './runtime/data/'; /** * 复写获取单一实例方法 - * @param null $dir + * @param string $dir * @return mixed */ - public static function instance($dir = null) + public static function instance($dir = '') { $ident = md5($dir); if (!isset(self::$instance[$ident])) { @@ -50,9 +49,9 @@ class File implements CacheIfs /** * 进行一些初始化操作 * File constructor. - * @param null $dir + * @param string $dir */ - private function __construct($dir = null) + private function __construct($dir = '') { if ($dir) { $this->dir = $dir; @@ -89,7 +88,7 @@ class File implements CacheIfs * @param null $callable * @return bool|false|string */ - public function get($key = null, $callable = null) + public function get($key, $callable = null) { // 判断缓存是否存在 if ($this->exists($key)) { @@ -107,7 +106,7 @@ class File implements CacheIfs * @param string $key * @return bool */ - public function remove($key = null) + public function remove($key) { $filename = $this->getFileName($key); if (is_file($filename)) { @@ -118,7 +117,7 @@ class File implements CacheIfs /** * 判断缓存是否存在/有效 - * @param $key + * @param string $key * @return bool */ public function exists($key) @@ -132,7 +131,7 @@ class File implements CacheIfs /** * 获取文件缓存内容 - * @param $key + * @param string $key * @return false|string */ private function getCacheContent($key) @@ -143,7 +142,7 @@ class File implements CacheIfs /** * 判断缓存是否超时 - * @param $key + * @param string $key * @return bool */ private function timeOut($key) @@ -169,7 +168,7 @@ class File implements CacheIfs /** * 读取缓存文件 - * @param $key + * @param string $key * @return mixed */ private function readCacheFile($key) diff --git a/framework/library/cache/driver/Redis.php b/framework/library/cache/driver/Redis.php index 635d0da..51e4b56 100644 --- a/framework/library/cache/driver/Redis.php +++ b/framework/library/cache/driver/Redis.php @@ -63,11 +63,11 @@ class Redis implements CacheIfs /** * 获取缓存的值 - * @param null $key - * @param null $callable + * @param string $key + * @param string $callable * @return bool|mixed|string */ - public function get($key = null, $callable = null) + public function get($key, $callable = null) { $status = $this->exists($key); $value = $status ? $this->redis->get($key) : false; @@ -89,7 +89,7 @@ class Redis implements CacheIfs * @param string $key * @return int */ - public function remove($key = null) + public function remove($key) { return $this->redis->del($key); } diff --git a/framework/library/cache/ifs/CacheIfs.php b/framework/library/cache/ifs/CacheIfs.php index 520a484..8bc1f49 100644 --- a/framework/library/cache/ifs/CacheIfs.php +++ b/framework/library/cache/ifs/CacheIfs.php @@ -5,9 +5,9 @@ namespace top\library\cache\ifs; interface CacheIfs { - public function set($name, $value, $timeout = null); + public function set($key, $value, $timeout = 0); - public function get($name = null, $callable = null); + public function get($key, $callable = null); - public function remove($name = null); + public function remove($key); }