当前位置:网站首页>Laravel 的 ORM 缓存包
Laravel 的 ORM 缓存包
2022-06-27 02:09:00 【lenixa】
Laravel 的 ORM 缓存包
LaraCache是一个基于 ORM 的 Laravel 包,用于基于模型查询创建、更新和管理缓存项。使用此包,您可以缓存在整个应用程序中大量使用的查询。
use Mostafaznv\LaraCache\Traits\LaraCache;
class Article extends Model
{
use LaraCache;
public static function cacheEntities(): array
{
return [
CacheEntity::make('list.forever')
->cache(function() {
return Article::query()->latest()->get();
}),
CacheEntity::make('latest')
->validForRestOfDay()
->cache(function() {
return Article::query()->latest()->first();
})
];
}
}使用该cacheEntities方法定义缓存查询,Laracache 将负责其余的工作。要使用缓存查询,您将调用模型,如下例所示:
use Mostafaznv\LaraCache\Facades\LaraCache;
$cache = Article::cache()->get('latest');
// or
$cache = LaraCache::retrieve(Article::class, 'latest');使用此软件包,您可以使用以下功能控制缓存:
- 启用/禁用缓存
- 手动更新缓存
- 手动更新所有缓存实体
- 删除缓存
CacheEntity使用流利的方法或ttl()方法控制持续时间
我认为以下手动缓存更新方法很简洁,可以即时刷新缓存:
Article::cache()->update('latest');
// or
LaraCache::update(Article::class, 'latest');边栏推荐
- Why divide the training set and the test set before normalization?
- 宁愿去996也不要待业在家啦!24岁,失业7个月,比上班更惨的,是没班可上
- Did your case really pass?
- Oracle/PLSQL: Rpad Function
- TechSmith Camtasia最新2022版详细功能讲解下载
- Memcached foundation 10
- Parameter transfer method between two pages
- Oracle/PLSQL: Soundex Function
- Cookie, sessionstorage, localstorage differences
- Memcached basics 14
猜你喜欢
随机推荐
DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?
Oracle/PLSQL: To_ Clob Function
Oracle/PLSQL: Upper Function
二叉树oj题目
H5 liquid animation JS special effect code
pytorch 23 hook的使用与介绍 及基于hook实现即插即用的DropBlock
Memcached Foundation 12
dat. gui. JS star circle track animation JS special effect
memcached基础14
Oracle/PLSQL: Lower Function
Oracle/PLSQL: Length Function
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
perl语言中 fork()、exec()、waitpid() 、 $? >> 8 组合
Oracle/PLSQL: Substr Function
Simply learn the entry-level concepts of googlecolab
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?
Nokov motion capture system makes it possible for multi field cooperative UAV to build independently
Some exception handling for idea plug-in development
UVM in UVM_ config_ Use of DB in sequence









