w7 / rangine-cache-model
对Model扩展缓存支持
Installs: 3 802
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- genealabs/laravel-model-caching: ^0.9.0
- w7/rangine: ^2.4.7
Requires (Dev)
- phpunit/phpunit: ^7.2
- w7/php-cs-fixer: *
This package is auto-updated.
Last update: 2024-12-09 15:05:24 UTC
README
使用说明
1. 注册 Psr\SimpleCache\CacheInterface
实现
\W7\Laravel\CacheModel\Caches\Cache::setCacheResolver(Cache::store());
2. 继承 W7\Laravel\CacheModel\Model
use W7\Laravel\CacheModel\Model;
class Member extends Model
{
public $timestamps = false;
protected $table = 'members';
protected $primaryKey = 'uid';
// 此行可缺省
protected $useCache = true;
}
3. 使用
find($id)
$uid = 1;
$user = Member::query()->find($uid);
$user = Member::query()->find($uid);
// query once
// select * from `ims_members` where `ims_members`.`uid` = ? limit 1
find($ids)
仅限指定 id 查询,不限定返回列。
$uids = [1, 2, 5];
Member::query()->find($uids);
Member::query()->find($uids);
// query once
// select * from `ims_members` where `ims_members`.`uid` in (?, ?, ?)
$model->save();
删除缓存。
$member = Member::find($uid)
$member->invite_code = rand(1, 100000);
$member->save();
$model->update();
删除缓存
$model->delete();
删除缓存
Member::flush();
清空指定表的缓存