cirelramos/cache-query-builder

它是一个提供查询生成和当使用特定方法时清除缓存的包

1.0.17 2023-01-03 19:41 UTC

This package is auto-updated.

Last update: 2024-09-04 07:47:12 UTC


README

Software License

关于

《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