riesenia / cakephp-fetchable
CakePHP ORM plugin for fetching entities from cache
Installs: 23 492
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
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
This plugin is for CakePHP 3.x and contains behavior that handles fetching entities from cache / memory storage. Relevant for tables that contain moderate number of rows and are used commonly in many parts of application.
Installation
Using composer
composer require riesenia/cakephp-fetchable
Usage
This behavior is suitable for tables that contain moderate number of rows
and are used commonly in many parts of application. Fetchable checks if they are
already cached and also stores them in memory using Configure
class. This lowers
the number of database queries for them.
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();
Configuration options:
- finder - finder to use to get entities. Defaults to "all".
- cache - cache config to use. Defaults to "default".
- contain - set related entities that will be fetched.
- key - key used for Cache and Configure calls. Can be set to callable (i.e. for I18n dependend data).