Skip to content

k-timoshenko/yii2-cache-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching static models component for Yii 2

Component allows easy cache and get static models data like statuses, cities or categories. There are methods to manually clear cache in purpose to update those data.

Install

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require --prefer-dist t-kanstantsin/yii2-cache-model "*"

or add

"t-kanstantsin/yii2-cache-model": "*"

to the require section of your composer.json file.

Usage

To configure component place this code in config's component definition:

    'cacheModel' => [
        'class' => tkanstantsin\cache\CacheModel::class, 
        'cache' => 'cache', // cache component
        'duration' => 86400, // caching time (it can't be greater than in 'cache' component)
    ],

List of all cached models by class name

\Yii::$app->cacheModel->get(foo\Foo::class);

Particular model

\Yii::$app->cacheModel->get(foo\Foo::class, $fooId);

Array of models

\Yii::$app->cacheModel->get(foo\Foo::class, [$fooId1, $fooId2]);

Manually clear cache

\Yii::$app->cacheModel->flush(foo\Foo::class);

Credits

License

The BSD License (BSD). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages