fengdangxing/hyperf-model-cache
最新稳定版本:v1.0.1
Composer 安装命令:
composer require fengdangxing/hyperf-model-cache
包简介
hyperf-db模型缓存、查询sql后自动缓存
README 文档
README
hyperf-db模型缓存、查询sql后自动缓存 #配置数据库app/databases.php
<?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @document https://hyperf.wiki * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ 'default' => [ 'driver' => env('DB_DRIVER', 'mysql'), 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'test'), 'port' => env('DB_PORT', 3306), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', 'root'), 'charset' => env('DB_CHARSET', 'utf8'), 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), 'prefix' => env('DB_PREFIX', ''), 'pool' => [ 'min_connections' => 1, 'max_connections' => 10, 'connect_timeout' => 10.0, 'wait_timeout' => 3.0, 'heartbeat' => -1, 'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60), ], 'commands' => [ 'gen:model' => [ 'path' => 'app/Model', 'force_casts' => true, 'inheritance' => 'Model', ], ], ], ];
#配置redis app/redis.php
<?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @document https://hyperf.wiki * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ 'default' => [ 'host' => env('REDIS_HOST', 'localhost'), 'auth' => env('REDIS_AUTH', null), 'port' => (int) env('REDIS_PORT', 6379), 'db' => (int) env('REDIS_DB', 0), 'pool' => [ 'min_connections' => 1, 'max_connections' => 50, 'connect_timeout' => 10.0, 'wait_timeout' => 3.0, 'heartbeat' => -1, 'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60), ], ] ];
#使用
<?php namespace App\Model; use Fengdangxing\ModelCache\ModelCache; class UserModel extends ModelCache { protected $table = 'user'; public static $redisList = 'user:list'; public static $redisInfo = 'user:info'; /** 配置回调关系表 */ public static function hasDelRedis() { //UserInfo::delRedis(); 关系表删除缓存 } /** * @Notes: 获取列表 * @param array $param * @param string[] $showFields * @return array */ public static function getPublishedList(array $param = [], array $showFields = ['*'], $isDeleted = false) { return self::getRow($param, $showFields, $page, $limit); } }
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-31