cirelramos / cache-query-builder
它是一个提供查询生成和当使用特定方法时清除缓存的包
1.0.17
2023-01-03 19:41 UTC
Requires
- php: ^7.4|^8.0
- cirelramos/logs: ^1.0
- illuminate/config: ^6.9|^7.0|^8.0|^9.0
- illuminate/console: ^6.9|^7.0|^8.0|^9.0
- illuminate/contracts: ^6.9|^7.0|^8.0|^9.0
- illuminate/database: ^6.9|^7.0|^8.0|^9.0
- illuminate/http: ^6.9|^7.0|^8.0|^9.0
- kirschbaum-development/eloquent-power-joins: ^2.5|^2.6
- spatie/laravel-query-builder: ^3.6|^5.0
README
关于
《cache-query-builder》包允许您提高性能并降低对数据库请求的压力。
如何创建composer包的教程
功能
- 缓存查询获取列和值
- 缓存子查询/关系
- 按模型设置单独的缓存时间
- 从缓存中获取和获取第一个值的方法
- 保存、插入、删除到缓存的方法
安装
在您的 composer.json
中要求 cirelramos/cache-query-builder
包,并更新您的依赖项
composer require cirelramos/cache-query-builder
配置
设置提供者
'providers' => [ // ... Cirelramos\Cache\Providers\ServiceProvider::class, ],
默认设置在 config/cache-query.php
中。发布配置以复制文件到您自己的配置
php artisan vendor:publish --provider="Cirelramos\Cache\Providers\ServiceProvider"
注意:这是必要的,以便您可以更改默认配置
使用方法
要缓存查询,您需要使用扩展类
class Product extends CacheModel { }
要缓存查询,您需要使用方法:getFromCache 或 firstCache
return Product::query() ->where('active', ModelConst::ENABLED) ->with($relations) ->getFromCache(['*'], $tags);
如果您想清除缓存,可以使用方法:saveWithCache、insertWithCache、deleteWithCache
$product = new Product(); $product->saveWithCache();
Product::insertWithCache($values);
$product->deleteWithCache();
许可
在MIT许可下发布,请参阅 LICENSE。