Битрикс: композитный кеш по условию

Хорошая штука композитный кеш в битриксе, но порой необходимо чтоб на странице были разные данные для, например, пользователей из разных групп. В данном примере, кеш создается в зависимости от cookie

Код класса который необходимо подключить в init.php

namespace Project\BitrixExtends;

class CacheProvider extends \Bitrix\Main\Data\StaticCacheProvider
{

    /**
     * @return string
     */
    public function getCachePrivateKey()
    {
        return self::getCachePrefix();
    }

    /**
     *
     */
    public function setUserPrivateKey()
    {
        \CHTMLPagesCache::setUserPrivateKey(self::getCachePrefix(), 0);
    }

    /**
     * @return bool
     */
    public function isCacheable()
    {
        return true;
    }

    /**
     *
     */
    public function onBeforeEndBufferContent()
    {
    }

    /**
     * @return string
     */
    public static function getCachePrefix()
    {
        global $APPLICATION;
        return ($APPLICATION->get_cookie("DESIGN_30") == "Y") ? 'standart' : 'design30';
    }

    /**
     * Установить Ключ КЕШа с учетом Куки дизайна.
     *
     * @return CacheProvider
     */
    public static function setCustomUserPrivateKey()
    {
        \CHTMLPagesCache::setUserPrivateKey(self::getCachePrefix(), 0);
        return new self();
    }
}

Код для сохранения cookie

if ($_GET["new_header"] == "Y") {
    $_COOKIE["BITRIX_SM_DESIGN_30"] = "Y";
    setcookie("BITRIX_SM_DESIGN_30", "Y", time() + (3600 * 24 * 30), "/");
}

Ну и вещаем на событие OnGetStaticCacheProvider

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler("main", "OnGetStaticCacheProvider", array(
    "\\Project\\BitrixExtends\\CacheProvider",
    "setCustomUserPrivateKey"
));

Взято отсюда: https://dev.1c-bitrix.ru/community/webdev/user/127124/blog/38176/