sergeymakinen/yii2-php-file-cache

This package is abandoned and no longer maintained. No replacement package was suggested.

Yii 2 PHP file cache

Maintainers

👁 sergeymakinen

Package info

github.com/sergeymakinen/yii2-php-file-cache

Type:yii2-extension

pkg:composer/sergeymakinen/yii2-php-file-cache

Statistics

Installs: 2 105

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

v2.1.0 2018-02-12 18:22 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT f9442024a9a5131fb51b4bcca3655de49a9e364b

phpfilecachecachingyiiyii2yii2-php-file-cache

This package is auto-updated.

Last update: 2022-12-16 00:58:01 UTC


README

Yii 2 cache component that uses native PHP files to store cache data so:

  • it's possible to improve a PHP performance by storing a precompiled data bytecode in a shared memory (objects will be serialized though)
  • allows to include an arbitrary PHP code to bootstrap something
  • it's fully compatible with the standard Yii 2 cache interface

👁 Code Quality
👁 Build Status
👁 Code Coverage
👁 SensioLabsInsight

👁 Packagist Version
👁 Total Downloads
👁 Software License

Installation

The preferred way to install this extension is through composer.

Either run

composer require "sergeymakinen/yii2-php-file-cache:^2.0"

or add

"sergeymakinen/yii2-php-file-cache": "^2.0"

to the require section of your composer.json file.

Usage

Set the following Yii 2 configuration parameters:

[
 'components' => [
 'phpCache' => [
 'class' => 'sergeymakinen\yii\phpfilecache\Cache',
 ],
 ],
]

And you can use it like any Yii 2 cache class:

Yii::$app->phpCache->set('foo', 'bar')

Caching values with a PHP code

If you need to execute any PHP bootstrap code before you get a value from a cache, pass a sergeymakinen\yii\phpfilecache\ValueWithBootstrap instance with the value and a PHP code (which can be multiline of course) as a string to set():

use sergeymakinen\yii\phpfilecache\ValueWithBootstrap;

Yii::$app->phpCache->set(
 'foo',
 new ValueWithBootstrap(
 'bar',
 'Yii::$app->params[\'fromCache\'] = true;'
 )
);

Since version 1.1 you can also pass a Closure instead of a PHP code:

use sergeymakinen\yii\phpfilecache\ValueWithBootstrap;
use yii\helpers\StringHelper;

Yii::$app->phpCache->set(
 'foo',
 new ValueWithBootstrap('bar', function () {
 \Yii::$app->params['fromCache'] = true;
 \Yii::$app->params['name'] = StringHelper::basename('/etc/config');
 })
)