当前位置: 首页>>代码示例>>PHP>>正文


PHP Data\Cache类代码示例

本文整理汇总了PHP中Bitrix\Main\Data\Cache的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getIblocks

/**
 * Обёртка, кэширующая результаты _getIblocks() в глобальный массив $arIb
 */
function getIblocks()
{
    global $arIb;
    $obCache = \Bitrix\Main\Data\Cache::createInstance();
    $cacheTime = 86400;
    $cacheId = md5('s1');
    $cachePath = "iblocks";
    if ($obCache->initCache($cacheTime, $cacheId, $cachePath)) {
        $vars = $obCache->getVars();
        $arIb = $vars["arIb"];
    } elseif ($obCache->startDataCache()) {
        $arIb = _getIblocks();
        $obCache->endDataCache(array("arIb" => $arIb));
    }
}
开发者ID:rschweppes,项目名称:bitrix-helpers,代码行数:18,代码来源:getiblocks.php

示例2: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dir = $input->getOption('dir');
     $tag = $input->getOption('tag');
     $cache = Cache::createInstance();
     if (empty($dir) && empty($tag)) {
         Application::getInstance()->getManagedCache()->cleanAll();
         $cache->cleanDir();
         $cache->cleanDir(false, 'stack_cache');
         StaticHtmlCache::getInstance()->deleteAll();
         if (Cache::clearCache(true)) {
             $output->writeln('<info>All Bitrix cache was deleted</info>');
         } else {
             $output->writeln('<error>Error deleting Bitrix cache</error>');
         }
     }
     if ($dir) {
         $cache->cleanDir($dir);
         $output->writeln('<info>Bitrix cache by "/' . BX_ROOT . '/cache/' . $dir . '" dir was deleted</info>');
     }
     if ($tag) {
         Application::getInstance()->getTaggedCache()->clearByTag($tag);
         $output->writeln('<info>Bitrix cache by tag "' . $tag . '" was deleted</info>');
     }
 }
开发者ID:notamedia,项目名称:console-jedi,代码行数:28,代码来源:ClearCommand.php

示例3: restoreDebugMode

 public static function restoreDebugMode()
 {
     global $DB, $APPLICATION;
     $toRestore = explode("|", constant("PERFMON_STARTED"));
     $DB->ShowSqlStat = $toRestore[0];
     \Bitrix\Main\Data\Cache::setShowCacheStat($toRestore[1]);
     $APPLICATION->ShowIncludeStat = $toRestore[2];
 }
开发者ID:rasuldev,项目名称:torino,代码行数:8,代码来源:keeper.php

示例4: read

 /**
  * @param bool $isArray
  * @return null
  */
 protected function read($isArray = false)
 {
     $value = $isArray ? array() : null;
     if (!$this->beenWrite && \Bitrix\Main\Data\Cache::shouldClearCache()) {
         $this->clear();
     }
     $this->timeLive && $this->original->read($value, $this->baseDir(), $this->bxInitDir, $this->key, $this->timeLive);
     return $value;
 }
开发者ID:Under5,项目名称:bitrix-module-tools,代码行数:13,代码来源:cache.php

示例5: getPropertiesEx

function getPropertiesEx($arParams)
{
    $obCache = \Bitrix\Main\Data\Cache::createInstance();
    $cacheTime = 86400;
    $cacheId = md5($arParams);
    $cachePath = "properties";
    $arProperties = array();
    if ($obCache->initCache($cacheTime, $cacheId, $cachePath)) {
        $vars = $obCache->getVars();
        $arProperties = $vars["arProperties"];
    } elseif ($obCache->startDataCache()) {
        $arProperties = _getPropertiesEx($arParams);
        $obCache->endDataCache(array("arProperties" => $arProperties));
    }
    return $arProperties;
}
开发者ID:rschweppes,项目名称:bitrix-helpers,代码行数:16,代码来源:getproperties.php

示例6: onUserSetLastActivityDate

 public function onUserSetLastActivityDate(\Bitrix\Main\Event $event)
 {
     $users = $event->getParameter(0);
     foreach ($users as $userId) {
         $cache = \Bitrix\Main\Data\Cache::createInstance();
         if ($cache->startDataCache(60, $userId, '/im/status')) {
             $mapper = \Bitrix\Replica\Mapper::getInstance();
             $map = $mapper->getByPrimaryValue("b_im_status.USER_ID", false, $userId);
             if ($map) {
                 $guid = \Bitrix\Replica\Client\User::getLocalUserGuid($userId);
                 if ($guid && $map[$guid]) {
                     $event = array("operation" => "im_status_update", "guid" => $guid);
                     \Bitrix\Replica\Log\Client::getInstance()->write($map[$guid], $event);
                 }
             }
             $cache->endDataCache(true);
         }
     }
 }
开发者ID:Satariall,项目名称:izurit,代码行数:19,代码来源:statushandler.php

示例7: getUserGroupWithStorage

 protected function getUserGroupWithStorage()
 {
     if (!\CBXFeatures::isFeatureEnabled("Workgroups")) {
         return array();
     }
     if (!Loader::includeModule('socialnetwork')) {
         return array();
     }
     $userId = $this->getUser()->getId();
     $currentPossibleUserGroups = $currentUserGroups = array();
     $cache = Cache::createInstance();
     $cacheTtl = defined('BX_COMP_MANAGED_CACHE') ? 3153600 : 3600 * 4;
     $cachePath = "/disk/uf/{$userId}";
     if ($cache->initCache($cacheTtl, 'group_storage_list_' . SITE_ID . '_' . $userId, $cachePath)) {
         list($currentUserGroups) = $cache->getVars();
     } else {
         $cache->startDataCache();
         $taggedCache = Application::getInstance()->getTaggedCache();
         $taggedCache->startTagCache($cachePath);
         $diskSecurityContext = new DiskSecurityContext($userId);
         $storages = Storage::getReadableList($diskSecurityContext, array('filter' => array('STORAGE.ENTITY_TYPE' => ProxyType\Group::className())));
         foreach ($storages as $storage) {
             $currentPossibleUserGroups[$storage->getEntityId()] = $storage;
         }
         unset($storage);
         $query = \CSocNetUserToGroup::getList(array('GROUP_NAME' => 'ASC'), array('USER_ID' => $userId, 'GROUP_ID' => array_keys($currentPossibleUserGroups)), false, false, array('GROUP_ID', 'GROUP_NAME', 'GROUP_ACTIVE', 'GROUP_CLOSED', 'ROLE'));
         while ($row = $query->getNext()) {
             if ($row['GROUP_ACTIVE'] == 'Y' && $row['GROUP_CLOSED'] == 'N' && $row['ROLE'] != SONET_ROLES_BAN && $row['ROLE'] != SONET_ROLES_REQUEST && isset($currentPossibleUserGroups[$row['GROUP_ID']])) {
                 $taggedCache->registerTag("sonet_features_G_{$row['GROUP_ID']}");
                 $taggedCache->registerTag("sonet_group_{$row['GROUP_ID']}");
                 $currentUserGroups[$row['GROUP_ID']] = array('STORAGE' => $currentPossibleUserGroups[$row['GROUP_ID']], 'NAME' => $row['GROUP_NAME']);
             }
         }
         $taggedCache->registerTag("sonet_user2group_U{$userId}");
         $taggedCache->endTagCache();
         $cache->endDataCache(array($currentUserGroups));
     }
     return $currentUserGroups;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:39,代码来源:controller.php

示例8: startResultCache

 /**
  * Function starts the caching block of the component execution.
  *
  * @param int|bool $cacheTime
  * @param mixed $additionalCacheID
  * @param string|bool $cachePath
  * @return string
  *
  */
 public final function startResultCache($cacheTime = false, $additionalCacheID = false, $cachePath = false)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION, $CACHE_MANAGER;
     if (!$this->__bInited) {
         return null;
     }
     if ($this->arParams["CACHE_TYPE"] == "N" || $this->arParams["CACHE_TYPE"] == "A" && COption::getOptionString("main", "component_cache_on", "Y") == "N") {
         return true;
     }
     if ($cacheTime === false) {
         $cacheTime = intval($this->arParams["CACHE_TIME"]);
     }
     $this->__cacheID = $this->getCacheID($additionalCacheID);
     $this->__cachePath = $cachePath;
     if ($this->__cachePath === false) {
         $this->__cachePath = $CACHE_MANAGER->getCompCachePath($this->__relativePath);
     }
     $this->__cache = \Bitrix\Main\Data\Cache::createInstance();
     if ($this->__cache->startDataCache($cacheTime, $this->__cacheID, $this->__cachePath)) {
         $this->__NavNum = $GLOBALS["NavNum"];
         if (defined("BX_COMP_MANAGED_CACHE") && $this->__cache->isStarted()) {
             $CACHE_MANAGER->startTagCache($this->__cachePath);
         }
         return true;
     } else {
         $arCache = $this->__cache->GetVars();
         $this->arResult = $arCache["arResult"];
         if (array_key_exists("templateCachedData", $arCache)) {
             $templateCachedData =& $arCache["templateCachedData"];
             if ($templateCachedData && is_array($templateCachedData)) {
                 if (array_key_exists("additionalCSS", $templateCachedData) && strlen($templateCachedData["additionalCSS"]) > 0) {
                     $APPLICATION->SetAdditionalCSS($templateCachedData["additionalCSS"]);
                     if ($this->__parent) {
                         $this->__parent->addChildCSS($templateCachedData["additionalCSS"]);
                     }
                 }
                 if (array_key_exists("additionalJS", $templateCachedData) && strlen($templateCachedData["additionalJS"]) > 0) {
                     $APPLICATION->AddHeadScript($templateCachedData["additionalJS"]);
                     if ($this->__parent) {
                         $this->__parent->addChildJS($templateCachedData["additionalJS"]);
                     }
                 }
                 if (array_key_exists("frames", $templateCachedData) && is_array($templateCachedData["frames"])) {
                     foreach ($templateCachedData["frames"] as $frameState) {
                         \Bitrix\Main\Page\FrameHelper::applyCachedData($frameState);
                     }
                 }
                 if (array_key_exists("frameMode", $templateCachedData) && $templateCachedData["frameMode"] === false) {
                     $context = isset($templateCachedData["frameModeCtx"]) ? "(from component cache) " . $templateCachedData["frameModeCtx"] : $this->__name . " - a cached template set frameMode=false";
                     \Bitrix\Main\Data\StaticHtmlCache::applyComponentFrameMode($context);
                 }
                 if (isset($templateCachedData["externalCss"])) {
                     foreach ($templateCachedData["externalCss"] as $cssPath) {
                         $APPLICATION->SetAdditionalCSS($cssPath);
                         //Check if parent component exists and plug css it to it's "collection"
                         if ($this->__parent) {
                             $this->__parent->addChildCSS($cssPath);
                         }
                     }
                 }
                 if (isset($templateCachedData["externalJs"])) {
                     foreach ($templateCachedData["externalJs"] as $jsPath) {
                         $APPLICATION->AddHeadScript($jsPath);
                         //Check if parent component exists and plug js it to it's "collection"
                         if ($this->__parent) {
                             $this->__parent->addChildJS($jsPath);
                         }
                     }
                 }
             }
             if ($templateCachedData["__editButtons"]) {
                 foreach ($templateCachedData["__editButtons"] as $button) {
                     if ($button[0] == 'AddEditAction') {
                         $this->addEditAction($button[1], $button[2], $button[3], $button[4]);
                     } else {
                         $this->addDeleteAction($button[1], $button[2], $button[3], $button[4]);
                     }
                 }
             }
             if ($templateCachedData["__view"]) {
                 foreach ($templateCachedData["__view"] as $view_id => $target) {
                     foreach ($target as $view_content) {
                         $APPLICATION->addViewContent($view_id, $view_content[0], $view_content[1]);
                     }
                 }
             }
             if (array_key_exists("__NavNum", $templateCachedData)) {
                 $GLOBALS["NavNum"] += $templateCachedData["__NavNum"];
             }
             if (array_key_exists("__children_css", $templateCachedData)) {
//.........这里部分代码省略.........
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:101,代码来源:component.php

示例9: getFromCache

 /**
  * Returns items from cache. If cache expired will be executed request to DB (method $this->getItems()).
  *
  * @param array $filter Parameters for filter.
  * @param string $shard Shard of the cache.
  *
  * @return mixed
  *
  * @throws ValueNotFoundException Value was not found.
  * @throws \InvalidArgumentException Invalid type on filter.
  */
 protected function getFromCache($filter = [], $shard = null)
 {
     $filter = $this->prepareFilter($filter);
     $cache = Cache::createInstance();
     if ($cache->initCache(static::getCacheTime(), null, static::getCacheDir() . '/' . $shard)) {
         $items = $cache->getVars();
     } else {
         $cache->startDataCache();
         Application::getInstance()->getTaggedCache()->startTagCache(static::getCacheDir() . '/' . $shard);
         $items = $this->getItems($shard);
         if (!empty($items)) {
             Application::getInstance()->getTaggedCache()->endTagCache();
             $cache->endDataCache($items);
         } else {
             $cache->abortDataCache();
         }
     }
     try {
         return $this->getValue($items, $filter, $shard);
     } catch (ValueNotFoundException $e) {
         if ($this->silenceMode) {
             return null;
         }
         throw $e;
     }
 }
开发者ID:bitrix-expert,项目名称:tools,代码行数:37,代码来源:Finder.php

示例10: loadFormattedFolderTreeAndBreadcrumbs

 private function loadFormattedFolderTreeAndBreadcrumbs($returnTree = false)
 {
     $cache = Data\Cache::createInstance();
     if ($cache->initCache(15768000, 'storage_tr_' . $this->storage->getId(), 'disk')) {
         list($formattedFolders, $this->cacheBreadcrumbs) = $cache->getVars();
     } else {
         $querySharedFolders = \Bitrix\Disk\Sharing::getList(array('filter' => array('FROM_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId(), '!TO_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId())));
         $sharedFolders = array();
         while ($sharedFolder = $querySharedFolders->fetch()) {
             $sharedFolders[$sharedFolder['REAL_OBJECT_ID']] = $sharedFolder['REAL_OBJECT_ID'];
         }
         $formattedFolders = array();
         foreach ($this->walkAndBuildTree($this->storage->getRootObject()) as $folder) {
             /** @var Folder $folder */
             $formattedFolders[] = $this->formatFolderToResponse($folder, isset($sharedFolders[$folder->getId()]));
         }
         unset($folder);
         $cache->startDataCache();
         $cache->endDataCache(array($formattedFolders, $this->cacheBreadcrumbs));
     }
     return $returnTree ? $formattedFolders : null;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:22,代码来源:diskstorage.php

示例11: Save

 public function Save()
 {
     if (defined("BITRIX_SKIP_STACK_CACHE") && BITRIX_SKIP_STACK_CACHE) {
         return;
     }
     global $DB;
     if (!$this->cleanSet || !$this->cleanGet && count($this->values) >= $this->len) {
         $objCache = \Bitrix\Main\Data\Cache::createInstance();
         //Force cache rewrite
         $saveClearState = $objCache->setClearCache(true);
         if ($objCache->StartDataCache($this->ttl, $this->entity, $DB->type . "/" . $this->entity, $this->values, "stack_cache")) {
             $objCache->EndDataCache();
         }
         $objCache->setClearCache($saveClearState);
         $this->cleanGet = true;
         $this->cleanSet = true;
     }
 }
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:18,代码来源:cache.php

示例12: define

 * @global CMain $APPLICATION
 * @global CDatabase $DB
 */
define("START_EXEC_EPILOG_AFTER_1", microtime());
$GLOBALS["BX_STATE"] = "EA";
global $USER, $APPLICATION, $DB;
foreach (GetModuleEvents("main", "OnEpilog", true) as $arEvent) {
    ExecuteModuleEventEx($arEvent);
}
$r = $APPLICATION->EndBufferContentMan();
$main_exec_time = round(getmicrotime() - START_EXEC_TIME, 4);
echo $r;
$arAllEvents = GetModuleEvents("main", "OnAfterEpilog", true);
define("START_EXEC_EVENTS_1", microtime());
$GLOBALS["BX_STATE"] = "EV";
CMain::EpilogActions();
define("START_EXEC_EVENTS_2", microtime());
$GLOBALS["BX_STATE"] = "EA";
foreach ($arAllEvents as $arEvent) {
    ExecuteModuleEventEx($arEvent);
}
if (!IsModuleInstalled("compression") && !defined("ADMIN_AJAX_MODE") && $_REQUEST["mode"] != 'excel') {
    $bShowTime = $_SESSION["SESS_SHOW_TIME_EXEC"] == 'Y';
    $bShowStat = $DB->ShowSqlStat && $USER->CanDoOperation('edit_php');
    $bShowCacheStat = \Bitrix\Main\Data\Cache::getShowCacheStat() && ($canEditPHP || $_SESSION["SHOW_CACHE_STAT"] == "Y");
    if ($bShowTime || $bShowStat || $bShowCacheStat) {
        include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/interface/debug_info.php";
    }
}
$DB->Disconnect();
CMain::ForkActions();
开发者ID:spas-viktor,项目名称:books,代码行数:31,代码来源:epilog_admin_after.php

示例13: getListEx

/**
 * Обёртка, кэширующая результаты _getListEx()
 *
 * Возможные параметры $arOptions:
 * - *iblock_id* - ID или символьный код инфоблока
 * - *filter* - Параметры фильтра
 * - *sort* - Параметры сортировки
 * - *select* - Поля для выборки
 * - *get_sections* - *true*, если нужно выбрать секции, а не элементы
 * - *id_key* - *true*, если ключи результирующего массива
 *              должны принять значения ID элемента:<br>
 *              <code>array(ID1 => array(...), ID2 => array(...))</code><br>
 *              Если параметр равен *false*, массив будет неассоциативным:<br>
 *              <code>array(array(...), array(...))</code>
 * - *is_sub_query* - Если *true*, результат выборки будет оформлен для фильтрации в другом _getListEx()
 * - *cache_time* - Время хранения кэша
 * - *nav* — Параметры для постраничной навигации, формируются, как в стандартном GetList()
 *           https://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockelement/getlist.php
 * 
 * @example getlistex.php Выбор всех компаний, у которых есть офис в Ярославле. Пример вложенных getListEx
 * @param  array $arOptions Параметры выборки
 * @return array            Массив с результатами выборки
 */
function getListEx($arOptions)
{
    $iblockId = iblock($arOptions['iblock_id']);
    if ($iblockId === false) {
        return false;
    }
    $obCache = \Bitrix\Main\Data\Cache::createInstance();
    $cacheTime = intval($arOptions['cache_time']) > 0 ? intval($arOptions['cache_time']) : 3600;
    $cacheId = md5(serialize($arOptions));
    $cachePath = '/lists_ex/' . $iblockId . '/';
    $arElements = array();
    if ($obCache->initCache($cacheTime, $cacheId, $cachePath)) {
        $vars = $obCache->getVars();
        $arElements = $vars['arElements'];
    } elseif ($obCache->startDataCache()) {
        global $CACHE_MANAGER;
        $CACHE_MANAGER->StartTagCache($cachePath);
        $CACHE_MANAGER->RegisterTag('iblock_id_' . $iblockId);
        $arElements = _getListEx($arOptions);
        foreach ($arElements as $arElement) {
            if (isset($arElement["ID"])) {
                $CACHE_MANAGER->RegisterTag("element_" . $arElement["ID"]);
            }
            if (!is_array($arElement) && intval($arElement) > 0) {
                $CACHE_MANAGER->RegisterTag("element_" . intval($arElement));
            }
        }
        $CACHE_MANAGER->EndTagCache();
        $obCache->endDataCache(array('arElements' => $arElements));
    }
    return $arElements;
}
开发者ID:rschweppes,项目名称:bitrix-helpers,代码行数:55,代码来源:getlist.php

示例14: getCache

 /**
  * Returns new instance of the Cache object.
  *
  * @return Data\Cache
  */
 public function getCache()
 {
     return \Bitrix\Main\Data\Cache::createInstance();
 }
开发者ID:ASDAFF,项目名称:bitrix-5,代码行数:9,代码来源:application.php

示例15: save

 public function save()
 {
     Config\Option::set('security', $this->optionPrefix . 'hosts', $this->hosts, '');
     Config\Option::set('security', $this->optionPrefix . 'action', $this->action, '');
     Config\Option::set('security', $this->optionPrefix . 'action_options', serialize($this->actionOptions), '');
     Config\Option::set('security', $this->optionPrefix . 'logging', $this->isLogNeeded, '');
     if (!is_null($this->isActive)) {
         if ($this->isActive) {
             EventManager::getInstance()->registerEventHandler('main', 'OnPageStart', 'security', get_class($this), 'onPageStart');
         } else {
             EventManager::getInstance()->unRegisterEventHandler('main', 'OnPageStart', 'security', get_class($this), 'onPageStart');
         }
     }
     Data\Cache::createInstance()->clean($this->cacheId);
 }
开发者ID:spas-viktor,项目名称:books,代码行数:15,代码来源:hostrestriction.php


注:本文中的Bitrix\Main\Data\Cache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。