flashytime / db-cache
A PHP library to cache database, supports MySQL,Mongo and Memcached,Redis...
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/flashytime/db-cache
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ^5
This package is not auto-updated.
Last update: 2025-10-23 23:03:32 UTC
README
A PHP library to cache database query, supports MySQL/Mongo and Memcached/Redis...
中文版
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
versionstrategy, which controls the creation and expiration of the cache
Installation
- Run the command below in your project root directory
composer require flashytime/db-cache
- Copy
config/db-cache.phpto your project config directory
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
MIT