geeky/query-cache-builder
Composer 安装命令:
composer require geeky/query-cache-builder
包简介
This package is caching every single query per request, to make sure that you will never duplicate your query again.
README 文档
README
If you are using Barryvdh's Debug Bar and you're seeing tons of duplicate queries, and you simply have no time to track them all down.
The package is caching all duplicates queries and it makes sure that you will never be executed the same query again, by overriding the method runSelect exsists in Illuminate\Database\Query\Builder that runs in every select query in Laravel, and we're going to cache every query by it's SQL and it's Bindings.
So instead of excuting a query, we will cache it as a key and it's results as a value.
If a query excutes, we will check if the query executed once before so we will retrieve the cached value or we will excute the query then cache it.
Installation
1- Install using composer:
composer require geeky/query-cache-builder
2- Add a custom Cache Driver. We're doing this so that we don't mess with any existing Cache logic you might already be using. In ~/config/cache.php add below cache stores array :
Note: you can use what you want of cache drivers.
'stores' => [
'cache-builder' => [
'driver' => 'file',
'path' => storage_path('framework/cache')
]
]
3- If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Geeky\Database\CacheBuilderServiceProvider::class
4- Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Geeky\Database\CacheBuilderServiceProvider"
This will publish the cachebuilder config file that gives you the ability to enable cahcing queries and the time you want to cache them.
Note: In case you used an array cache driver the quires will be cached in-memory Cache store that just stores everything inside an array. This is typically wiped at the end of each request,as once the application gives a response, this is naturally freed from memory. so it doesn't matter if you edit the minutes to 0 or any integer number.
<?php
return [
'enable' => true,
'minutes' => 1, // 0 or null will cache all quieris forever
];
Usage
Use the CacheQueryBuilder trait in any model you want to use this feature.
<?php
namespace App;
use Geeky\Database\CacheQueryBuilder;
use Illuminate\Database\Eloquent\Model;
class SomeModel extends Model
{
use CacheQueryBuilder;
}
Use the below command if you want to flush the cache of our custom store
php artisan cache-builder:clear
geeky/query-cache-builder 适用场景与选型建议
geeky/query-cache-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83.05k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2018 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「cache」 「laravel」 「Query Cache」 「laravel duplicate query」 「query cache builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 geeky/query-cache-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 geeky/query-cache-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 geeky/query-cache-builder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
repository php library
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 83.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-13