本文整理汇总了PHP中Cms\Classes\Page::useCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::useCache方法的具体用法?PHP Page::useCache怎么用?PHP Page::useCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cms\Classes\Page
的用法示例。
在下文中一共展示了Page::useCache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrlPageName
public function getUrlPageName()
{
if (static::$urlPageName !== null) {
return static::$urlPageName;
}
/*
* Cache
*/
$key = 'urlMaker' . $this->urlComponentName . crc32(get_class($this));
$cached = Cache::get($key, false);
if ($cached !== false && ($cached = @unserialize($cached)) !== false) {
$filePath = array_get($cached, 'path');
$mtime = array_get($cached, 'mtime');
if (!File::isFile($filePath) || $mtime != File::lastModified($filePath)) {
$cached = false;
}
}
if ($cached !== false) {
return static::$urlPageName = array_get($cached, 'fileName');
}
$page = Page::useCache()->whereComponent($this->urlComponentName, 'isPrimary', '1')->first();
if (!$page) {
throw new ApplicationException(sprintf('Unable to a find a primary component "%s" for generating a URL in %s.', $this->urlComponentName, get_class($this)));
}
$baseFileName = $page->getBaseFileName();
$filePath = $page->getFullPath();
$cached = ['path' => $filePath, 'fileName' => $baseFileName, 'mtime' => @File::lastModified($filePath)];
Cache::put($key, serialize($cached), Config::get('cms.parsedPageCacheTTL', 1440));
return static::$urlPageName = $baseFileName;
}