grafite / query-cache
A database query caching system with invalidation automation.
Requires
- php: ^8.2
- illuminate/collections: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- laravel/legacy-factories: ^1.4
- laravel/pint: ^1.10
- livewire/livewire: dev-main
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0|^10.0|^11.0
- phpunit/phpunit: ^11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
QueryCache - A general query result caching system for Eloquent models.
QueryCache is a general query result caching system for Eloquent models. It's optimized to be as automated as possible, and can work with Redis and SQLite as caching.
Author(s):
- Matt Lantz (@mattylantz, mattlantz at gmail dot com)
Requirements
- PHP 8.2+
Compatibility and Support
| Laravel Version | Package Tag | Supported |
|---|---|---|
| ^11.x - ^12.x | 1.x | yes |
Installation
Start a new Laravel project:
composer create-project laravel/laravel your-project-name
Then run the following to add Support
composer require "grafite/query-cache"
Documentation
https://documentation.grafite.ca/docs/utilities-querycache
Transactions
Queries run inside a database transaction bypass the cache, since they may see uncommitted data. Cache flushes triggered by model writes inside a transaction are deferred until it commits, and all writes in that transaction share a single flush (a rollback flushes nothing). Set skip_in_transactions (QUERY_CACHE_SKIP_IN_TRANSACTIONS) to false to cache inside transactions, e.g. when your test suite wraps every test in one.
Memoization limit
Repeated identical queries within a request are served from memory. memoize_limit (QUERY_CACHE_MEMOIZE_LIMIT, default 1000) caps how many results are held, evicting the oldest first, so long-running commands stay bounded.
Upgrading
Hashed cache keys now use xxh128 instead of md5, so existing cached queries will miss once after upgrading.
License
Support is open-sourced software licensed under the MIT license
Bug Reporting and Feature Requests
Please add as many details as possible regarding submission of issues and feature requests
Disclaimer
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
