承接 webo3/laravel-db-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webo3/laravel-db-cache

Composer 安装命令:

composer require webo3/laravel-db-cache

包简介

Transparent database query caching for Laravel — zero code changes, smart invalidation, multi-driver.

README 文档

README

Transparent database query caching for Laravel — zero code changes, smart invalidation, multi-driver.

The package intercepts queries at the connection level: SELECT results are cached, and any mutation (INSERT, UPDATE, DELETE, …) automatically invalidates the cached queries that reference the same tables. Your application code doesn't change.

Features

  • Zero-config caching — works transparently at the database connection level
  • Smart invalidation — mutations invalidate exactly the cached queries that touch the affected tables
  • Three driversarray (per-request), redis (persistent, two-tier L1/L2), null (no-op)
  • Multi-tenant isolationsetTenantContext() namespaces cache keys per tenant, with an opt-in fail-safe
  • Safe by default — never caches transactions, locking reads, nondeterministic queries (NOW(), RAND(), nextval(), …) or cursors; Redis payloads are HMAC-signed with APP_KEY
  • Production-ready Redis driver — circuit breaker on outages, TTL jitter, O(1) table-based invalidation, AWS ElastiCache / Valkey compatible

Requirements

PHP 8.1+ · Laravel 9–12 · MySQL, PostgreSQL or SQLite · Redis (optional, for the redis driver)

Installation

composer require webo3/laravel-db-cache

The service provider is auto-discovered. Optionally publish the config:

php artisan vendor:publish --tag=db-cache-config

Quick start

Add to your .env:

DB_QUERY_CACHE_ENABLED=true
DB_QUERY_CACHE_DRIVER=array

That's it — SELECTs on your default mysql connection are now cached for the duration of each request. For a persistent cache shared across workers, switch to the Redis driver.

Configuration

Variable Default Description
DB_QUERY_CACHE_ENABLED false Enable/disable query caching
DB_QUERY_CACHE_DRIVER array Cache driver: array, redis, or null
DB_QUERY_CACHE_TTL 180 Cache time-to-live in seconds
DB_QUERY_CACHE_CONNECTION mysql Connection name(s) to cache (comma-separated for several)
DB_QUERY_CACHE_EXCLUDED_TABLES (empty) Identifiers (views, etc.) that must never be cached
DB_QUERY_CACHE_LOG_ENABLED false Cache hit/miss/invalidation logging + stats middleware
DB_QUERY_CACHE_TENANT_REQUIRED false Bypass caching until setTenantContext() is called (multi-tenant fail-safe)

The full reference (Redis connection, size limits, runtime API) lives in docs/configuration.md.

Artisan commands

php artisan db-cache:clear   # clear the cache (all tenant namespaces)
php artisan db-cache:prune   # remove stale index references (redis); schedule hourly

Good to know

  • Reads are eventually consistent: a cached result can be at most ttl seconds stale. Keep the TTL short for write-heavy tables.
  • The cache is transaction-aware: SELECTs inside a transaction are never cached, and invalidation defers to COMMIT (dropped on ROLLBACK).
  • SQL views can't be auto-invalidated — list them in DB_QUERY_CACHE_EXCLUDED_TABLES.
  • Redis Cluster is not supported; point the driver at a single Redis node/database.

Details in docs/how-it-works.md.

Documentation

Guide Contents
Configuration Full config reference, drivers, multiple connections, excluded views, long-running workers (Octane/Horizon)
Redis driver Connection setup, TLS/ElastiCache, predis vs phpredis, igbinary, pruning, cluster caveat
Multi-tenancy Tenant-scoped caching, per-driver behavior, the tenant_required fail-safe
Usage & monitoring Programmatic API, stats middleware, artisan commands, custom drivers
How it works Caching pipeline, query normalization, consistency model and caveats

Testing

composer install
vendor/bin/phpunit

Tests need a MySQL connection (copy .env.example to .env); Redis tests skip automatically when Redis is unavailable.

License

MIT

webo3/laravel-db-cache 适用场景与选型建议

webo3/laravel-db-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 565 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「performance」 「cache」 「mysql」 「sqlite」 「postgresql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 webo3/laravel-db-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webo3/laravel-db-cache 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 565
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-07