geeky/query-cache-builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Screenshot

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.

Screenshot

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 geeky/query-cache-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 83.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-13