Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca;
|
||||
|
||||
use Bitrix\Main\Application;
|
||||
use Bitrix\Main\Data\Cache;
|
||||
|
||||
final class Cached
|
||||
{
|
||||
public static function remember(string $dir, string $id, int $ttl, array $tags, callable $load): mixed
|
||||
{
|
||||
$cache = Cache::createInstance();
|
||||
if ($cache->initCache($ttl, $id, $dir)) {
|
||||
return $cache->getVars();
|
||||
}
|
||||
|
||||
$cache->startDataCache();
|
||||
$taggedCache = Application::getInstance()->getTaggedCache();
|
||||
$taggedCache->startTagCache($dir);
|
||||
try {
|
||||
foreach ($tags as $tag) {
|
||||
$taggedCache->registerTag($tag);
|
||||
}
|
||||
$value = $load();
|
||||
} catch (\Throwable $e) {
|
||||
$taggedCache->abortTagCache();
|
||||
$cache->abortDataCache();
|
||||
throw $e;
|
||||
}
|
||||
$taggedCache->endTagCache();
|
||||
$cache->endDataCache($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user