← Все статьи

Кеш и тегированный сброс

PHP
<?php

use Bitrix\Main\Data\Cache;
use Bitrix\Main\Application;

$cache = Cache::createInstance();
$cacheId = 'deal_stats_' . $userId;
$cacheDir = '/local/deal_stats';

if ($cache->initCache(3600, $cacheId, $cacheDir)) {
    $result = $cache->getVars();
} elseif ($cache->startDataCache()) {
    $result = ['count' => 10];
    $tagged = Application::getInstance()->getTaggedCache();
    $tagged->startTagCache($cacheDir);
    $tagged->registerTag('crm_deal_list');
    $tagged->endTagCache();
    $cache->endDataCache($result);
}