当前位置:网站首页>ORM cache package for laravel
ORM cache package for laravel
2022-06-27 02:15:00 【lenixa】
Laravel Of ORM Cache package
LaraCache It's based on ORM Of Laravel package , Used to create... Based on model queries 、 Update and manage cache entries . Use this package , You can cache queries that are heavily used throughout your application .
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();
})
];
}
} Use this cacheEntities Method to define a cache query ,Laracache Will be responsible for the rest of the work . To use cached queries , You will invoke the model , As shown in the following example :
use Mostafaznv\LaraCache\Facades\LaraCache;
$cache = Article::cache()->get('latest');
// or
$cache = LaraCache::retrieve(Article::class, 'latest');Use this package , You can use the following functions to control the cache :
- Enable / Disable caching
- Manually update cache
- Manually update all cached entities
- Delete cache
CacheEntityUse fluent methods orttl()Method control duration
I think the following manual cache update method is simple , The cache can be refreshed immediately :
Article::cache()->update('latest');
// or
LaraCache::update(Article::class, 'latest');You can learn about this bag , Get complete installation instructions , And in GitHub Check out Source code .
边栏推荐
- 解决cherry pick提交报错问题
- 学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息
- pytorch 22 8种Dropout方法的简介 及 基于Dropout用4行代码快速实现DropBlock
- pytorch 23 hook的使用与介绍 及基于hook实现即插即用的DropBlock
- LeetCode 785:判断二分图
- Oracle/PLSQL: To_Clob Function
- Oracle/PLSQL: Translate Function
- 【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数
- Oracle/PLSQL: NumToDSInterval Function
- Binary tree OJ problem
猜你喜欢

Enterprise digital transformation: informatization and digitalization

【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数

h5液体动画js特效代码

按键控制LED状态翻转

three.js多米诺骨牌js特效

Is the division of each capability domain of Dama, dcmm and other data management frameworks reasonable? Is there internal logic?

p5.js死亡星球

消费者追捧iPhone,在于它的性价比超越国产手机

dat.gui.js星星圆圈轨迹动画js特效

ThreadLocal详解
随机推荐
Flink学习2:应用场景
为什么传递SPIF_SENDCHANGE标志SystemParametersInfo会挂起?
Oracle/PLSQL: Trim Function
Oracle/PLSQL: Substr Function
Simply learn the entry-level concepts of googlecolab
YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
Oracle/PLSQL: Cast Function
Shell script series (1) getting started
Some exception handling for idea plug-in development
mmdetection 用yolox训练自己的coco数据集
Reading a book in idea is too much!
参数估计——《概率论及其数理统计》第七章学习报告(点估计)
Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?
Memcached foundation 10
消费者追捧iPhone,在于它的性价比超越国产手机
学习太极创客 — MQTT(七)MQTT 主题进阶
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
Oracle/PLSQL: Rtrim Function
p5.js死亡星球
ThreadLocal详解