karelwintersky/arris.cache

Arris µFramework Cache Redis wrapper

0.99.0 2024-07-20 09:03 UTC

This package is auto-updated.

Last update: 2024-12-20 09:49:25 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

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