PHP code example of alex19pov31 / bitrix-redis-cache

1. Go to this page and download the library: Download alex19pov31/bitrix-redis-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alex19pov31 / bitrix-redis-cache example snippets



return [
  'cache' => [
    'value' => [
      'type' => [
          'class_name' => 'Alex19pov31\BitrixRedisCache\RedisCacheEngine',
        ],
      'redis' => [
        'scheme' => 'tcp',
        'host' => '127.0.0.1',
        'port' => 6379,
      ],
      'sid' => $_SERVER["DOCUMENT_ROOT"]."#01"
    ],
  ],
];

use Bitrix\Main\Data\Cache;

$data = null;
$ttl = 3600; // кешируем на час
$key = "test_key"; // ключ кеша

$cache = Cache::createInstance();
if ($cache->initCache($ttl, $key, 'redis')) {
    $data = $cache->getVars();
    // или если имело место быть кеширование вывода
    $cache->output();
} elseif ($cache->startDataCache($ttl, $key, 'redis', [])) {
	$data = 'Тестовые данные';
	$cache->endDataCache($data);
}