karelwintersky/arris.cache

Arris µFramework Cache Redis wrapper

v0.5.2 2022-02-03 14:40 UTC

This package is auto-updated.

Last update: 2022-05-01 00:17:00 UTC


README

Arris µFramework Cache Redis wrapper

use Arris\Cache\Cache;
use Arris\DB;
use Arris\AppLogger;

$pdo_connection = new PDO('');
// or $pdo_connection = DB::getConnection();

Cache::init([
    'enabled'   =>  getenv('REDIS.ENABLED'),
    'host'      =>  getenv('REDIS.HOST'),
    'port'      =>  getenv('REDIS.PORT'),
    'password'  =>  getenv('REDIS.PASSWORD'),
    'database'  =>  getenv('REDIS.DATABASE')
], [
    'districts' =>  [
        'source'    =>  'sql',
        'action'    =>  'SELECT id, name FROM districts WHERE hidden = 0 ORDER BY id ASC',
        'ttl'       =>  86400
    ],
    'rubrics'   =>  [
        'source'    =>  'sql',
        'action'    =>  'SELECT id, name, url FROM rubrics WHERE hidden = 0 ORDER BY sorder',
        'ttl'       =>  86400
    ],
    'Articles.getLatest100' =>  [
        'source'    =>  'callback',
        'action'    =>  [ "\FSNews\Units\Articles@getLeftLatestArticles", [ 100 ] ],
        'ttl'       =>  50
    ],
], $pdo_connection, AppLogger::scope('redis'));

Правило типа 'callback' может быть:

Class@method Class::method customFunction instance of Closure

Параметры передаются всегда массивом.