flashytime / db-cache
一个用于缓存数据库的PHP库,支持MySQL、Mongo和Memcached、Redis...
v1.0.0
2018-05-11 08:48 UTC
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ^5
This package is not auto-updated.
Last update: 2024-09-26 17:41:53 UTC
README
一个用于缓存数据库查询的PHP库,支持MySQL/Mongo和Memcached/Redis...
中文版
特性
- 支持常见数据库,如MySQL、Mongo
- 支持常见缓存服务器,如Memcached、Redis
- 支持数据库主从和读写分离
- 支持MySQL数据库表分片
- 通过
版本策略管理缓存,控制缓存的创建和过期
安装
- 在项目根目录下运行以下命令
composer require flashytime/db-cache
- 将
config/db-cache.php复制到您的项目配置目录
用法
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'; } }
许可证
MIT