承接 jonathan-neugber/cake-variable-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jonathan-neugber/cake-variable-cache

Composer 安装命令:

composer require jonathan-neugber/cake-variable-cache

包简介

A simple config based variable cache plugin for CakePHP 3

README 文档

README

License

Description

This plugin is designed to asynchronously execute calculations that take a long amount of time and save the results (e.g.: Statistics).

It allows you to create a simple list of variables that are to be calculated every n-amount of time.

It also supports dependent variables (e.g.: variable bar requires variable foo to be calculated first).

Installation

1. require the plugin in your composer.json

	"require": {
		...
		"jonathan-neugber/cake-variable-cache": "dev-master",
		...
	}

2. Include the plugin using composer

Open a terminal in your project-folder and run these commands:

$ composer update
$ composer install

3. Load the plugin in your config/bootstrap.php

Plugin::load('VariableCache', ['bootstrap' => true]);

4. Add configuration to your config/app.php

use Josegonzalez\CakeQueuesadilla\Queue\Queue;
use VariableCache\Lib\Engine\DatabaseCacheProvider;
use VariableCache\Lib\QueuesadillaCallbacks;
use VariableCache\Model\Entity\CachedVariable;
        'VariableCache' => [
            'DataProvider' => [
                'className' => DatabaseCacheProvider::class
            ],
            'Queue' => [
                'callback' => function (CachedVariable $variable) {
                    return Queue::push([
                        QueuesadillaCallbacks::class,
                        'executeJob'
                    ], [
                        'name' => $variable->name
                    ]);
                }
            ],
            'variables' => []
        ]

5. Migrations

Open a terminal in your project-folder and run this command:

$ bin/cake migrations migrate --source=../vendor/jonathan-neugber/cake-variable-cache/config/Migrations/

Usage / Example

1. Create a callback

Lets say you want to calculate a statistic:

class Statistic
{
    public static function calculateStatistic($name, $amount)
    {
        return 20000 * $amount;
    }
}

2. Create a config

In the VariableCache.variables section of the configuration add the following:

'foo' => [
    'callback' => ['\Statistics', 'calculateStatistic'],
    'interval' => '5 minutes',
    'args' => [
        200 // this will be passed as the first argument
    ],
    'variables' => [
        'bar' => [
            'callback' => ['\Statistics', 'calculateStatistic'],
            'interval' => '30 seconds',
            'args' => [
                100
            ]
        ]
    ]
]

3. Import the config

Open a terminal in your project-folder and run this command:

$ bin/cake VariableCache.CachedVariables update

This will create the cached variables in the Database.

4. Run the queues

Execute the following commands in parallel in a terminal in your project-folder and run this command:

$ bin/cake VariableCache.CachedVariables

and

$ bin/cake queuesadilla

5. Access the variable

$foo = CachedVariableUtility::get('foo');
$foo->content; // value

OR

$data = CachedVariableUtility::getMultiple(['foo', 'bar']);

OR

// Returns an array with name => value
$data = CachedVariableUtility::getAsKeyValue(['foo', 'bar']);

Additional Information

DynamicCalculationTrait

The DynamicCalculationTrait allows you to easily create a library of callbacks for cached variables. Using DynamicCalculationTrait::calculate() as the callback will automatically call the function calculate<CachedVariableName> in the class.

Example:
class Statistic
{
    use DynamicCalculationTrait;

    public static function calculateFoo($amount)
    {
        return 20000 * $amount;
    }

    public static function calculateBar($amount)
    {
        return CachedVariableUtility::get('foo')->content * $amount;
    }
}
'foo' => [
    'callback' => ['\Statistics', 'calculate'],
    'interval' => '5 minutes',
    'args' => [
        200 // this will be passed as the first argument
    ],
    'variables' => [
        'bar' => [
            'callback' => ['\Statistics', 'calculate'],
            'interval' => '30 seconds',
            'args' => [
                100
            ]
        ]
    ]
]

Reset

This will reset all main cached variables so that a new execution is required.

$ bin/cake VariableCache.CachedVariables reset

TODO

  • Write more tests
  • Use mock class for CacheProviderInterface
  • Test Cache Providers separately
  • Update documentation

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固