vemcogroup / model-cache
静态缓存而非重新访问缓存服务器
1.0.1
2020-12-01 10:34 UTC
Requires
- php: >=7.1
This package is auto-updated.
Last update: 2024-08-29 04:54:48 UTC
README
描述
此包允许在您的模型上拥有静态本地缓存。
它既可以与缓存服务器一起使用,也可以不使用。
安装
您可以通过composer安装此包
composer require vemcogroup/model-cache
使用方法
在您的类中使用特性非常简单,只需按以下方式使用特性即可
use Vemcogroup\ModelCache\Traits\HaslocalCache; class DataRepository { use HasLocalCache; public function getData($userId) { $localCacheKey = 'getData.'.$userId; /* * If localCache exists with key return cache */ if ($cache = self::getLocalCache($localCacheKey)) { return $cache; } // Run DB query or Cache code $result = [1, 2, 3, 4, 5, 6]; /* * Remember to save your DB query or Cache result */ self::setLocalCache($localCacheKey, $result); return $result; } }
如果您需要清除缓存,可以使用clear方法
self::clearLocalCache();