riesenia / cakephp-fetchable
CakePHP ORM 插件,用于从缓存中获取实体
v2.0.1
2019-12-26 01:29 UTC
Requires
- php: >=7.1
- cakephp/orm: ^3.5
Requires (Dev)
- cakephp/cakephp: ^3.5
- friendsofphp/php-cs-fixer: ~2.0
- phpstan/phpstan: ~0.11
- phpunit/phpunit: ^5.7.14|^6.0
- rshop/php-cs-fixer-config: ~2.0
README
此插件适用于 CakePHP 3.x,包含处理从缓存/内存存储中获取实体的行为。适用于包含中等数量行且在应用程序的许多部分中常用的表。
安装
使用 composer
composer require riesenia/cakephp-fetchable
用法
此行为适用于包含中等数量行且在应用程序的许多部分中常用的表。Fetchable 会检查它们是否已经缓存,并使用 Configure
类将它们存储在内存中。这减少了它们的数据库查询次数。
class StatusesTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->addBehavior('Fetchable.Fetchable', [ // can use custom finder 'finder' => 'active', // cache config 'cache' => 'statuses_cache', // can contain another data 'contain' => ['StatusProperties'], // if i.e. status name is translatable 'key' => function ($name) { return $name . '-' . I18n::getLocale(); } ]); } } // fetch all active statuses $this->Statuses->fetch();
配置选项
- finder - 用于获取实体的查找器。默认为 "all"。
- cache - 要使用的缓存配置。默认为 "default"。
- contain - 设置要获取的相关实体。
- key - 用于 Cache 和 Configure 调用的键。可以设置为可调用(即对于 I18n 依赖的数据)。