本文整理汇总了PHP中Bitrix\Main\Data\Cache::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::createInstance方法的具体用法?PHP Cache::createInstance怎么用?PHP Cache::createInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Main\Data\Cache
的用法示例。
在下文中一共展示了Cache::createInstance方法的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));
}
}
示例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>');
}
}
示例3: 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;
}
示例4: 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);
}
}
}
示例5: 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;
}
示例6: __construct
public function __construct()
{
$this->cache = \Bitrix\Main\Data\Cache::createInstance();
}
示例7: getCache
/**
* Returns new instance of the Cache object.
*
* @return Data\Cache
*/
public function getCache()
{
return \Bitrix\Main\Data\Cache::createInstance();
}
示例8: 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;
}
}
示例9: 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)) {
//.........这里部分代码省略.........
示例10: getCache
/**
* Returns new instance of the Cache object.
*
* @return Data\Cache
*/
public static function getCache()
{
return Data\Cache::createInstance();
}
示例11: 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;
}
示例12: intval
}
}
######################################################
######################################################
######################################################
if (!isset($arParams['CACHE_TIME'])) {
$arParams['CACHE_TIME'] = 999999;
}
if (!isset($arParams['CACHE_TYPE'])) {
$arParams['CACHE_TYPE'] = 'A';
}
// obtain cached data
$cacheNeeded = intval($arParams['CACHE_TIME']) > 0 && $arParams['CACHE_TYPE'] != 'N' && \Bitrix\Main\Config\Option::get("main", "component_cache_on", "Y") == "Y";
$cachedData = array();
if ($cacheNeeded) {
$currentCache = \Bitrix\Main\Data\Cache::createInstance();
$cacheDir = '/sale/location/legacy/component/sal';
if ($currentCache->startDataCache(intval($arParams['CACHE_TIME']), implode('|', array_merge($arParams, array(SITE_ID, LANGUAGE_ID))), $cacheDir)) {
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache($cacheDir);
try {
$cachedData['ZONE_IDS'] = SalesZone::getSelectedIds($arParams["SITE_ID"]);
$cachedData['DEFAULT_LOCS'] = array();
$res = CSaleLocation::GetList(array("SORT" => "ASC", "COUNTRY_NAME_LANG" => "ASC", "CITY_NAME_LANG" => "ASC"), array("LOC_DEFAULT" => "Y", "LID" => LANGUAGE_ID), false, false, array("*"));
while ($item = $res->fetch()) {
$cachedData['DEFAULT_LOCS'][] = $item;
}
} catch (Exception $e) {
if ($cacheNeeded) {
$CACHE_MANAGER->AbortTagCache();
$currentCache->abortDataCache();
示例13: 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"];
CBitrixComponentTemplate::applyCachedData($templateCachedData);
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)) {
foreach ($templateCachedData["__children_css"] as $css_url) {
$APPLICATION->setAdditionalCSS($css_url);
}
}
if (array_key_exists("__children_js", $templateCachedData)) {
foreach ($templateCachedData["__children_js"] as $js_url) {
$APPLICATION->addHeadScript($js_url);
}
}
if (array_key_exists("__children_epilogs", $templateCachedData)) {
foreach ($templateCachedData["__children_epilogs"] as $component_epilog) {
$this->includeComponentEpilog($component_epilog);
}
}
if (array_key_exists("component_epilog", $templateCachedData)) {
$this->includeComponentEpilog($templateCachedData["component_epilog"]);
}
}
return false;
}
}
示例14: clearByTag
public function clearByTag($tag)
{
$con = Main\Application::getConnection();
$sqlHelper = $con->getSqlHelper();
if ($tag === true) {
$sqlWhere = " WHERE TAG <> '*'";
} else {
$sqlWhere = " WHERE TAG = '" . $sqlHelper->forSql($tag) . "'";
}
$arDirs = array();
$rs = $con->query("SELECT * FROM b_cache_tag" . $sqlWhere);
while ($ar = $rs->fetch()) {
$arDirs[$ar["RELATIVE_PATH"]] = $ar;
}
$con->queryExecute("DELETE FROM b_cache_tag" . $sqlWhere);
$cache = Cache::createInstance();
$managedCache = Main\Application::getInstance()->getManagedCache();
foreach ($arDirs as $path => $ar) {
$con->queryExecute("\n\t\t\t\tDELETE FROM b_cache_tag\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($ar["SITE_ID"]) . "'\n\t\t\t\tAND CACHE_SALT = '" . $sqlHelper->forSql($ar["CACHE_SALT"]) . "'\n\t\t\t\tAND RELATIVE_PATH = '" . $sqlHelper->forSql($ar["RELATIVE_PATH"]) . "'\n\t\t\t");
if (preg_match("/^managed:(.+)\$/", $path, $match)) {
$managedCache->cleanDir($match[1]);
} else {
$cache->cleanDir($path);
}
unset($this->dbCacheTags[$path]);
}
}
示例15: cleanCacheTreeBitrixDisk
/**
* Cleans cache with folders tree.
*
* @internal
* @deprecated
* @param array $storageIds List of storage id.
* @return void
*/
public function cleanCacheTreeBitrixDisk(array $storageIds)
{
$cache = Cache::createInstance();
foreach ($storageIds as $id) {
$cache->clean('storage_tr_' . $id, 'disk');
}
unset($id);
}