本文整理汇总了PHP中CPHPCache::initCache方法的典型用法代码示例。如果您正苦于以下问题:PHP CPHPCache::initCache方法的具体用法?PHP CPHPCache::initCache怎么用?PHP CPHPCache::initCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPHPCache
的用法示例。
在下文中一共展示了CPHPCache::initCache方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getActiveTest
/**
* Returns active A/B-test
*
* @return array|null
*/
public static function getActiveTest()
{
static $abtest;
if (!defined('SITE_ID') || !SITE_ID) {
return null;
}
if (empty($abtest)) {
$cache = new \CPHPCache();
if ($cache->initCache(30 * 24 * 3600, 'abtest_active_' . SITE_ID, '/abtest')) {
$abtest = $cache->getVars();
} else {
$abtest = ABTestTable::getList(array('order' => array('SORT' => 'ASC'), 'filter' => array('SITE_ID' => SITE_ID, 'ACTIVE' => 'Y', '<=START_DATE' => new \Bitrix\Main\Type\DateTime())))->fetch() ?: null;
$cache->startDataCache();
$cache->endDataCache($abtest);
}
if (!empty($abtest) && intval($abtest['DURATION']) > 0) {
$end = clone $abtest['START_DATE'];
$end->add(intval($abtest['DURATION']) . ' days');
if (time() > $end->format('U')) {
Helper::stopTest($abtest['ID'], true);
$abtest = null;
}
}
}
return $abtest;
}
示例2: canRead
/**
* @param $userId
* @return bool
*/
public function canRead($userId)
{
if ($this->canRead !== null) {
return $this->canRead;
}
if (!Loader::includeModule('socialnetwork')) {
return false;
}
$cacheTtl = 2592000;
$cacheId = 'blog_post_socnet_general_' . $this->entityId . '_' . LANGUAGE_ID;
$timezoneOffset = \CTimeZone::getOffset();
if ($timezoneOffset != 0) {
$cacheId .= "_" . $timezoneOffset;
}
$cacheDir = '/blog/socnet_post/gen/' . intval($this->entityId / 100) . '/' . $this->entityId;
$cache = new \CPHPCache();
if ($cache->initCache($cacheTtl, $cacheId, $cacheDir)) {
$post = $cache->getVars();
} else {
$cache->startDataCache();
$queryPost = \CBlogPost::getList(array(), array("ID" => $this->entityId), false, false, array("ID", "BLOG_ID", "PUBLISH_STATUS", "TITLE", "AUTHOR_ID", "ENABLE_COMMENTS", "NUM_COMMENTS", "VIEWS", "CODE", "MICRO", "DETAIL_TEXT", "DATE_PUBLISH", "CATEGORY_ID", "HAS_SOCNET_ALL", "HAS_TAGS", "HAS_IMAGES", "HAS_PROPS", "HAS_COMMENT_IMAGES"));
$post = $queryPost->fetch();
$cache->endDataCache($post);
}
if (!$post) {
$this->canRead = false;
return false;
}
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
$this->canRead = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]) >= BLOG_PERMS_READ;
return $this->canRead;
}
示例3: parsePath
protected function parsePath($requestUri)
{
static $storages;
if (empty($storages)) {
$cache = new \CPHPCache();
if ($cache->initCache(30 * 24 * 3600, 'webdav_disk_common_storage', '/webdav/storage')) {
$storages = $cache->getVars();
} else {
$storages = \Bitrix\Disk\Storage::getModelList(array('filter' => array('=ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className())));
foreach ($storages as $key => $storage) {
$storages[$key] = array('id' => $storage->getEntityId(), 'path' => $storage->getProxyType()->getStorageBaseUrl());
}
$cache->startDataCache();
if (defined('BX_COMP_MANAGED_CACHE')) {
$taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
$taggedCache->startTagCache('/webdav/storage');
$taggedCache->registerTag('disk_common_storage');
$taggedCache->endTagCache();
}
$cache->endDataCache($storages);
}
}
$patterns = array(array('user', '/(?:company|contacts)/personal/user/(\\d+)/files/lib(.*)$'), array('user', '/(?:company|contacts)/personal/user/(\\d+)/disk/path(.*)$'), array('group', '/workgroups/group/(\\d+)/files(.*)$'), array('group', '/workgroups/group/(\\d+)/disk/path(.*)$'));
foreach ($storages as $storage) {
$storagePath = trim($storage['path'], '/');
$patterns[] = array('docs', sprintf('^/%s/path(.*)$', $storagePath), $storage['id']);
$patterns[] = array('docs', sprintf('^/%s(.*)$', $storagePath), $storage['id']);
}
// @TODO: aggregator
$patterns[] = array('docs', '^/docs/path(.*)$', 'shared_files_s1');
$patterns[] = array('docs', '^/docs(.*)$', 'shared_files_s1');
$type = null;
$id = null;
$path = null;
foreach ($patterns as $pattern) {
$matches = array();
if (preg_match('#' . $pattern[1] . '#i', $requestUri, $matches)) {
$type = $pattern[0];
list($id, $path) = $type == 'docs' ? array($pattern[2], $matches[1]) : array($matches[1], $matches[2]);
break;
}
}
/** @var Storage $storage */
$storage = null;
if ($type == 'user') {
$storage = Driver::getInstance()->getStorageByUserId((int) $id);
} elseif ($type == 'group') {
$storage = Driver::getInstance()->getStorageByGroupId((int) $id);
} elseif ($type == 'docs') {
$storage = Driver::getInstance()->getStorageByCommonId($id);
} else {
return array(null, null);
}
$path = static::UrlDecode($path);
return array($storage, $path);
}
示例4: initCache
/**
* Init CPHPCache and return status of initialization
* @param $cntStartCacheId
* @return bool
*/
protected function initCache($cntStartCacheId)
{
$this->cacheDir = '/' . SITE_ID . $this->getRelativePath() . '/' . substr(md5($cntStartCacheId), 0, 5) . '/' . trim(CDBResult::NavStringForCache($this->arParams['USERS_PER_PAGE'], false), '|');
$this->cacheId = $this->getName() . '|' . SITE_ID;
if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) {
$this->cacheId .= '|' . $this->getUser()->GetID() . '|' . $this->arParams['EXTRANET_TYPE'];
}
$this->cacheId .= CDBResult::NavStringForCache($this->arParams['USERS_PER_PAGE'], false) . $cntStartCacheId . "|" . $this->arParams['USERS_PER_PAGE'];
$this->obCache = new CPHPCache();
return $this->obCache->initCache($this->arParams['CACHE_TIME'], $this->cacheId, $this->cacheDir);
}
示例5: getActiveTest
/**
* Returns active A/B-test
*
* @return array|null
*/
public static function getActiveTest()
{
static $abtest;
static $defined;
if (!defined('SITE_ID') || !SITE_ID) {
return null;
}
if (empty($defined)) {
$cache = new \CPHPCache();
if ($cache->initCache(30 * 24 * 3600, 'abtest_active_' . SITE_ID, '/abtest')) {
$abtest = $cache->getVars();
} else {
$abtest = ABTestTable::getList(array('order' => array('SORT' => 'ASC'), 'filter' => array('SITE_ID' => SITE_ID, 'ACTIVE' => 'Y', '<=START_DATE' => new Type\DateTime())))->fetch() ?: null;
$cache->startDataCache();
$cache->endDataCache($abtest);
}
$defined = true;
if (!empty($abtest)) {
if (!$abtest['MIN_AMOUNT']) {
$capacity = AdminHelper::getSiteCapacity($abtest['SITE_ID']);
if ($capacity['min'] > 0) {
$result = ABTestTable::update($abtest['ID'], array('MIN_AMOUNT' => $capacity['min']));
if ($result->isSuccess()) {
$cache->clean('abtest_active_' . SITE_ID, '/abtest');
$abtest['MIN_AMOUNT'] = $capacity['min'];
}
}
}
if (intval($abtest['DURATION']) == -1) {
if (intval($abtest['MIN_AMOUNT']) > 0) {
$capacity = AdminHelper::getTestCapacity($abtest['ID']);
if ($capacity['A'] >= $abtest['MIN_AMOUNT'] && $capacity['B'] >= $abtest['MIN_AMOUNT']) {
Helper::stopTest($abtest['ID'], true);
$abtest = null;
}
}
} else {
if (intval($abtest['DURATION']) > 0) {
$end = clone $abtest['START_DATE'];
$end->add(intval($abtest['DURATION']) . ' days');
if (time() > $end->format('U')) {
Helper::stopTest($abtest['ID'], true);
$abtest = null;
}
}
}
}
}
return $abtest;
}
示例6: getTestCapacity
/**
* Returns A/B-test traffic amounts
*
* @param int $id A/B-test ID.
* @return array
*/
public static function getTestCapacity($id)
{
$cache = new \CPHPCache();
if ($cache->initCache(time() - strtotime('today'), 'abtest_capacity_' . intval($id), '/abtest')) {
$capacity = $cache->getVars();
} else {
if (Loader::includeModule('conversion')) {
if ($conversionRates = Conversion\RateManager::getTypes(array('ACTIVE' => true))) {
if ($abtest = ABTestTable::getById($id)->fetch()) {
$lid = $abtest['SITE_ID'];
$baseRate = array_slice($conversionRates, 0, 1, true);
$reportContext = new Conversion\ReportContext();
$reportContext->setAttribute('conversion_site', $lid);
$reportContext->setAttribute('abtest', $id);
$reportContext->setAttribute('abtest_section', 'A');
$groupAData = reset($reportContext->getRatesDeprecated($baseRate, array(), null));
$reportContext->unsetAttribute('abtest_section', 'A');
$reportContext->setAttribute('abtest_section', 'B');
$groupBData = reset($reportContext->getRatesDeprecated($baseRate, array(), null));
$capacity = array('A' => $groupAData['DENOMINATOR'], 'B' => $groupBData['DENOMINATOR']);
$cache->startDataCache(strtotime('tomorrow') - time());
$cache->endDataCache($capacity);
}
}
}
}
return !empty($capacity) ? $capacity : array('A' => 0, 'B' => 0);
}
示例7: getDataToCheck
private static function getDataToCheck($messageId)
{
$return = false;
if ($messageId > 0 && Loader::includeModule("forum")) {
if (!array_key_exists($messageId, self::$messages)) {
$cacheTtl = 2592000;
$cacheId = 'forum_message_' . $messageId;
$cachePath = \CComponentEngine::makeComponentPath("forum.topic.read");
$cache = new \CPHPCache();
$messages = $topics = array();
if ($cache->initCache($cacheTtl, $cacheId, $cachePath)) {
list($messages, $topics) = $cache->getVars();
} else {
$dbRes = \CForumMessage::getListEx(array("ID" => "ASC"), array("TOPIC" => "Y", "TOPIC_MESSAGE_ID" => $messageId, ">=ID" => $messageId), false, 10);
while ($res = $dbRes->fetch()) {
$messages["M" . $res["ID"]] = array_intersect_key($res, array("ID" => "", "TOPIC_ID" => "", "FORUM_ID" => "", "USER_ID" => "", "NEW_TOPIC" => "", "PARAM1" => "", "PARAM2" => ""));
if (!array_key_exists("T" . $res["TOPIC_ID"], $topics)) {
$topics["T" . $res["TOPIC_ID"]] = array("TITLE" => $res["TITLE"], "USER_ID" => $res["USER_START_ID"], "XML_ID" => $res["TOPIC_XML_ID"], "SOCNET_GROUP_ID" => $res["TOPIC_SOCNET_GROUP_ID"], "OWNER_ID" => $res["TOPIC_OWNER_ID"]);
}
}
if (!empty($messages)) {
$cache->startDataCache();
$res = reset($topics);
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
\CForumCacheManager::setTag($cachePath, "forum_topic_" . $res['ID']);
$cache->endDataCache(array($messages, $topics));
}
}
self::$messages += $messages;
self::$topics += $topics;
}
if (array_key_exists("M" . $messageId, self::$messages)) {
$return = array(self::$messages["M" . $messageId], self::$topics["T" . self::$messages["M" . $messageId]["TOPIC_ID"]], \CForumNew::getByIDEx(self::$messages["M" . $messageId]["FORUM_ID"], SITE_ID));
}
}
return $return;
}