PHPackages                             flashytime/db-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. flashytime/db-cache

ActiveLibrary[Caching](/categories/caching)

flashytime/db-cache
===================

A PHP library to cache database, supports MySQL,Mongo and Memcached,Redis...

v1.0.0(8y ago)1131MITPHPPHP &gt;=5.6

Since May 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/flashytime/db-cache)[ Packagist](https://packagist.org/packages/flashytime/db-cache)[ RSS](/packages/flashytime-db-cache/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

db-cache
========

[](#db-cache)

A PHP library to cache database query, supports MySQL/Mongo and Memcached/Redis...

##### [中文版](https://github.com/flashytime/db-cache/blob/master/README.zh-cn.md)

[](#中文版)

### Features

[](#features)

- Supports common databases, such as MySQL、Mongo
- Supports common cache servers, such as Memcached、Redis
- Supports database master-slave and reading/writing separation
- Supports MySQL database table sharding
- Manage cache through a `version` strategy, which controls the creation and expiration of the cache

### Installation

[](#installation)

- Run the command below in your project root directory

```
composer require flashytime/db-cache
```

- Copy `config/db-cache.php` to your project config directory

### Usage

[](#usage)

```
class TestModel
{
    public $dbCache;

    public function __construct()
    {
        // you can get the config in your own way
        $config = $this->getConfig();
        $this->dbCache = new \Flashytime\DbCache\DbCache($config, 'Test', ['name' => 'test', 'primary' => 'id']);
    }

    public function create($data)
    {
        return $this->dbCache->insert($data);
    }

    public function getById($id)
    {
        return $this->dbCache->select(['where' => 'id = :id'], ['id' => $id]);
    }

    public function findAll($offset, $limit)
    {
        return $this->dbCache->all(['limit' => ':offset, :limit', 'order' => 'id DESC'], ['offset' => $offset, 'limit' => $limit]);
    }

    public function updateById($id, $data)
    {
        return $this->dbCache->update(['where' => 'id = :id'], ['id' => $id], $data);
    }

    public function remove($id)
    {
        return $this->dbCache->delete(['where' => 'id = :id'], ['id' => $id]);
    }

    public function getConfig()
    {
        //path to your config directory
        return require __DIR__ . '/../config/db-cache.php';
    }
}
```

### License

[](#license)

MIT

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3019d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4725967?v=4)[flashytime](/maintainers/flashytime)[@flashytime](https://github.com/flashytime)

---

Top Contributors

[![flashytime](https://avatars.githubusercontent.com/u/4725967?v=4)](https://github.com/flashytime "flashytime (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flashytime-db-cache/health.svg)

```
[![Health](https://phpackages.com/badges/flashytime-db-cache/health.svg)](https://phpackages.com/packages/flashytime-db-cache)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975175.4k2](/packages/awssat-laravel-visits)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15196.8k7](/packages/rapidwebltd-rw-file-cache)[yuzuru-s/redis-recommend

Wrapping Redis's sorted set APIs for specializing recommending operations.

392.9k](/packages/yuzuru-s-redis-recommend)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
