curder/laravel-query-cache
Composer 安装命令:
composer require curder/laravel-query-cache
包简介
Cache all {select} queries or only the duplicate ones for a specific Eloquent model
README 文档
README
Cache all "select" queries or only the duplicate ones for a specific Eloquent model
Overview
This package allows you to cache all queries of type select, or only just the duplicated ones for an Eloquent model.
Please note that because cache tagging is used, "file" or "database" cache drivers are incompatible with this package.
Compatible cache stores: array, redis, apc, memcached
Tested cache stores: array, redis
Installation
Install the package via Composer:
composer require curder/laravel-query-cache
Publish the config file with:
php artisan vendor:publish --provider="Neurony\QueryCache\ServiceProvider" --tag="config"
Please read the
config/query-cache.phpconfig file comments as it contains extra information
Usage
Step 1
Your Eloquent models should use the Neurony\QueryCache\Traits\IsCacheable trait.
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Neurony\QueryCache\Traits\IsCacheable; class YourModel extends Model { use IsCacheable; }
Step 2
In your .env file add the necessary environment variables:
# The driver used for storing the cache keys that this package generates.
# This driver can differ from your main Laravel's CACHE_DRIVER.
QUERY_CACHE_DRIVER=redis
# Wether to cache absolutely all queries for the current request.
CACHE_ALL_QUERIES=true
# Wether to cache only the duplicated queries for the current request.
CACHE_DUPLICATE_QUERIES=true
Depending on how you set your environment variables, the next time you make select queries on that Eloquent model, after the very first run, the queries will be cached.
Extra
Using the QueryCacheService class
Please note that the Neurony\QueryCache\Services\QueryCacheService class is the actual implementation of the Neurony\QueryCache\Contracts\QueryCacheServiceContract interface.
The Neurony\QueryCache\Services\QueryCacheService class is bound to the Laravel's IoC as a singleton and aliased as cache.query.
With that being said, the recommended way of directly using the Neurony\QueryCache\Services\QueryCacheService is:
app('cache.query'); // or app(QueryCacheServiceContract::class);
Enable / Disable query caching
You can enable or disable all query caching for your current request, by calling the enableQueryCache or disableQueryCache methods present on the Neurony\QueryCache\Services\QueryCacheService class.
// from her on, no queries will be cached app('cache.query')->disableQueryCache(); /* make your queries the queries up until now won't be cached */ // from her on, apply query caching app('cache.query')->enableQueryCache(); /* make your queries this queries will be cached */
Flush query cache
You can flush the query cache by using the flush:query-cache artisan command.
Flush all query cache:
php artisan flush:query-cache
Flush query cache only for a specific model:
php artisan flush:query-cache --model=App/YourModel
# or
php artisan flush:query-cache --model=App\\YourModel
Credits
Security
If you discover any security related issues, please email andrei.badea@neurony.ro instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
curder/laravel-query-cache 适用场景与选型建议
curder/laravel-query-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.53k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「query」 「model」 「laravel」 「eloquent」 「duplicate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 curder/laravel-query-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 curder/laravel-query-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 curder/laravel-query-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
Interfaces for web resource models and services to retrieve and create them
Anax Database Active Record module for model classes.
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 1.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-07