limingxinleo / swoft-entity-cache
Swoft 模型实体缓存
Installs: 1 610
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
- swoft/db: ^1.0
- swoft/framework: ^1.0.25
- swoft/redis: ^1.0.15
Requires (Dev)
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^5.7
- swoft/swoole-ide-helper: dev-master
README
Swoft 模型实体缓存
环境变量
# 实体缓存超时时间 ENTITY_CACHE_TTL=3600 # 模型缓存前缀 ENTITY_PREFIX=prefix
使用
config/properties/app.php中增加对应自定义组件
return [
...
'components' => [
'custom' => [
'Swoftx\\Db\\Entity\\',
],
],
];
修改实体基类,增加ModelCacheable Trait
<?php /** * Swoft Entity Cache * * @author limx <715557344@qq.com> * @link https://github.com/limingxinleo/swoft-entity-cache */ namespace App\Models; use Swoft\Db\Model; use Swoftx\Db\Entity\ModelCacheable; class ModelCache extends Model { use ModelCacheable; }
调用
<?php // 从Redis中拿模型实体 $user = User::findOneByCache(1);