本文整理汇总了PHP中Pimcore\Model\Cache::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::save方法的具体用法?PHP Cache::save怎么用?PHP Cache::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Model\Cache
的用法示例。
在下文中一共展示了Cache::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($config)
{
if (!(string) $config->disableDefaultTenant) {
$this->defaultWorker = new OnlineShop_Framework_IndexService_Tenant_Worker_DefaultMysql(new OnlineShop_Framework_IndexService_Tenant_Config_DefaultMysql("default", $config));
}
$this->tenantWorkers = array();
if ($config->tenants && $config->tenants instanceof Zend_Config) {
foreach ($config->tenants as $name => $tenant) {
$tenantConfigClass = (string) $tenant->class;
$tenantConfig = $tenant;
if ($tenant->file) {
if (!($tenantConfig = \Pimcore\Model\Cache::load("onlineshop_config_assortment_tenant_" . $tenantConfigClass))) {
$tenantConfig = new Zend_Config_Xml(PIMCORE_DOCUMENT_ROOT . (string) $tenant->file, null, true);
$tenantConfig = $tenantConfig->tenant;
\Pimcore\Model\Cache::save($tenantConfig, "onlineshop_config_assortment_tenant_" . $tenantConfigClass, array("ecommerceconfig"), 9999);
}
}
/**
* @var $tenantConfig OnlineShop_Framework_IndexService_Tenant_IConfig
*/
$tenantConfig = new $tenantConfigClass($name, $tenantConfig, $config);
$worker = $tenantConfig->getTenantWorker();
$this->tenantWorkers[$name] = $worker;
}
}
}
示例2: dispatchLoopShutdown
/**
*
*/
public function dispatchLoopShutdown()
{
$code = (string) $this->getResponse()->getHttpResponseCode();
if ($code && ($code[0] == "4" || $code[0] == "5")) {
$this->writeLog();
// put the response into the cache, this is read in Pimcore_Controller_Action_Frontend::checkForErrors()
$responseData = $this->getResponse()->getBody();
if (strlen($responseData) > 20) {
$cacheKey = "error_page_response_" . \Pimcore\Tool\Frontend::getSiteKey();
\Pimcore\Model\Cache::save($responseData, $cacheKey, array("output"), 900, 9992);
}
}
}
示例3: save
/**
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = 0)
{
$key = $this->transformCacheKey($id);
if ($lifeTime === 0) {
// Pimcore's cache lifetime is infinite if it's null, Doctrine's is if it's 0
$lifeTime = 999999;
}
try {
SystemCache::save($data, $key, ["pimcore_doctrine_cache_drive"], $lifeTime);
return true;
} catch (\Exception $e) {
return false;
}
}
示例4: __construct
/**
* @param $domain
*/
public function __construct($domain)
{
$this->_domain = $domain;
try {
$robotsUrl = $domain . '/robots.txt';
$cacheKey = "robots_" . crc32($robotsUrl);
if (!($robotsTxt = Cache::load($cacheKey))) {
$robotsTxt = \Pimcore\Tool::getHttpData($robotsUrl);
Cache::save($robotsTxt, $cacheKey, array("system"), 3600, 999, true);
}
$this->_rules = $this->_makeRules($robotsTxt);
} catch (\Exception $e) {
}
}
示例5: load
/**
*
*/
public function load()
{
$client = Api::getSimpleClient();
$config = $this->getConfig();
$perPage = $this->getPerPage();
$offset = $this->getOffset();
$query = $this->getQuery();
if ($client) {
$search = new \Google_Service_Customsearch($client);
// determine language
$language = "";
if (\Zend_Registry::isRegistered("Zend_Locale")) {
$locale = \Zend_Registry::get("Zend_Locale");
$language = $locale->getLanguage();
}
if (!array_key_exists("hl", $config) && !empty($language)) {
$config["hl"] = $language;
}
if (!array_key_exists("lr", $config) && !empty($language)) {
$config["lr"] = "lang_" . $language;
}
if ($query) {
if ($offset) {
$config["start"] = $offset + 1;
}
if (empty($perPage)) {
$perPage = 10;
}
$config["num"] = $perPage;
$cacheKey = "google_cse_" . md5($query . serialize($config));
// this is just a protection so that no query get's sent twice in a request (loops, ...)
if (\Zend_Registry::isRegistered($cacheKey)) {
$result = \Zend_Registry::get($cacheKey);
} else {
if (!($result = Cache::load($cacheKey))) {
$result = $search->cse->listCse($query, $config);
Cache::save($result, $cacheKey, array("google_cse"), 3600, 999);
\Zend_Registry::set($cacheKey, $result);
}
}
$this->readGoogleResponse($result);
return $this->getResults(false);
}
return array();
} else {
throw new \Exception("Google Simple API Key is not configured in System-Settings.");
}
}
示例6: saveToMockupCache
/**
* updates mockup cache, delegates creation of mockup object to tenant config
*
* @param $objectId
* @param null $data
* @return OnlineShop_Framework_ProductList_DefaultMockup
*/
public function saveToMockupCache($objectId, $data = null)
{
if (empty($data)) {
$data = $this->db->fetchOne("SELECT data FROM " . $this->getStoreTableName() . " WHERE id = ? AND tenant = ?", array($objectId, $this->name));
$data = json_decode($data, true);
}
$mockup = $this->tenantConfig->createMockupObject($objectId, $data['data'], $data['relations']);
$key = $this->createMockupCacheKey($objectId);
$success = \Pimcore\Model\Cache::save(serialize($mockup), $key, [$this->getMockupCachePrefix()], null, 0, true);
$result = \Pimcore\Model\Cache::load($key);
if ($success && $result) {
$this->db->query("UPDATE " . $this->getStoreTableName() . " SET crc_index = crc_current WHERE id = ? and tenant = ?", array($objectId, $this->name));
} else {
Logger::err("Element with ID {$objectId} could not be added to mockup-cache");
}
return $mockup;
}
示例7: __construct
/**
* @param Zend_Config $config -> configuration to contain
* @param string $identifier -> cache identifier for caching sub files
*/
public function __construct(Zend_Config $config, $identifier)
{
$this->defaultConfig = $config;
foreach ((array) $config->tenants as $tenantName => $tenantConfig) {
if ($tenantConfig instanceof Zend_Config) {
if ($tenantConfig->file) {
$cacheKey = "onlineshop_config_" . $identifier . "_checkout_tenant_" . $tenantName;
if (!($tenantConfigFile = \Pimcore\Model\Cache::load($cacheKey))) {
$tenantConfigFile = new Zend_Config_Xml(PIMCORE_DOCUMENT_ROOT . (string) $tenantConfig->file, null, true);
$tenantConfigFile = $tenantConfigFile->tenant;
\Pimcore\Model\Cache::save($tenantConfigFile, $cacheKey, array("ecommerceconfig"), 9999);
}
$this->tenantConfigs[$tenantName] = $tenantConfigFile;
} else {
$this->tenantConfigs[$tenantName] = $tenantConfig;
}
}
}
}
示例8: _loadTranslationData
/**
* @param null $data
* @param $locale
* @param array $options
* @return array
*/
protected function _loadTranslationData($data, $locale, array $options = array())
{
$locale = (string) $locale;
$tmpKeyParts = explode("\\", self::getBackend());
$cacheKey = "Translate_" . array_pop($tmpKeyParts) . "_data_" . $locale;
if (!($data = Cache::load($cacheKey))) {
$data = array("__pimcore_dummy" => "only_a_dummy");
$listClass = self::getBackend() . "\\Listing";
$list = new $listClass();
if ($list->isCacheable()) {
$list->setCondition("language = ?", array($locale));
$translations = $list->loadRaw();
foreach ($translations as $translation) {
$data[mb_strtolower($translation["key"])] = Tool\Text::removeLineBreaks($translation["text"]);
}
Cache::save($data, $cacheKey, array("translator", "translator_website", "translate"), null, 999);
$this->isCacheable = true;
} else {
$this->isCacheable = false;
}
}
$this->_translate[$locale] = $data;
return $this->_translate;
}
示例9: getAllTranslations
/**
* @return array|mixed
*/
public function getAllTranslations()
{
$cacheKey = static::getTableName() . "_data";
if (!($translations = Cache::load($cacheKey))) {
$itemClass = static::getItemClass();
$translations = array();
$translationsData = $this->db->fetchAll("SELECT * FROM " . static::getTableName());
foreach ($translationsData as $t) {
if (!$translations[$t["key"]]) {
$translations[$t["key"]] = new $itemClass();
$translations[$t["key"]]->setKey($t["key"]);
}
$translations[$t["key"]]->addTranslation($t["language"], $t["text"]);
//for legacy support
if ($translations[$t["key"]]->getDate() < $t["creationDate"]) {
$translations[$t["key"]]->setDate($t["creationDate"]);
}
$translations[$t["key"]]->setCreationDate($t["creationDate"]);
$translations[$t["key"]]->setModificationDate($t["modificationDate"]);
}
Cache::save($translations, $cacheKey, array("translator", "translate"), 999);
}
return $translations;
}
示例10: getNavigation
/**
* @param $activeDocument
* @param null $navigationRootDocument
* @param null $htmlMenuIdPrefix
* @param null $pageCallback
* @param bool|string $cache
* @return mixed|\Zend_Navigation
* @throws \Exception
* @throws \Zend_Navigation_Exception
*/
public function getNavigation($activeDocument, $navigationRootDocument = null, $htmlMenuIdPrefix = null, $pageCallback = null, $cache = true)
{
$cacheEnabled = (bool) $cache;
$this->_htmlMenuIdPrefix = $htmlMenuIdPrefix;
if (!$navigationRootDocument) {
$navigationRootDocument = Document::getById(1);
}
$siteSuffix = "";
if (Site::isSiteRequest()) {
$site = Site::getCurrentSite();
$siteSuffix = "__site_" . $site->getId();
}
$cacheId = $navigationRootDocument->getId();
if (is_string($cache)) {
$cacheId .= "_" . $cache;
}
$cacheKey = "navigation_" . $cacheId . $siteSuffix;
$navigation = CacheManager::load($cacheKey);
if (!$navigation || !$cacheEnabled) {
$navigation = new \Zend_Navigation();
if ($navigationRootDocument->hasChilds()) {
$rootPage = $this->buildNextLevel($navigationRootDocument, true, $pageCallback);
$navigation->addPages($rootPage);
}
// we need to force caching here, otherwise the active classes and other settings will be set and later
// also written into cache (pass-by-reference) ... when serializing the data directly here, we don't have this problem
if ($cacheEnabled) {
CacheManager::save($navigation, $cacheKey, ["output", "navigation"], null, 999, true);
}
}
// set active path
$activePage = $navigation->findOneBy("realFullPath", $activeDocument->getRealFullPath());
if (!$activePage) {
// find by link target
$activePage = $navigation->findOneBy("uri", $activeDocument->getRealFullPath());
}
if ($activePage) {
// we found an active document, so we can build the active trail by getting respectively the parent
$this->addActiveCssClasses($activePage, true);
} else {
// we don't have an active document, so we try to build the trail on our own
$allPages = $navigation->findAllBy("uri", "/.*/", true);
foreach ($allPages as $page) {
$activeTrail = false;
if (strpos($activeDocument->getRealFullPath(), $page->getRealFullPath() . "/") === 0) {
$activeTrail = true;
}
if ($page->getDocumentType() == "link") {
if (strpos($activeDocument->getFullPath(), $page->getUri() . "/") === 0) {
$activeTrail = true;
}
}
if ($activeTrail) {
$page->setActive(true);
$page->setClass($page->getClass() . " active active-trail");
}
}
}
return $navigation;
}
示例11: getProperties
/**
* @return Property[]
*/
public function getProperties()
{
if ($this->o_properties === null) {
// try to get from cache
$cacheKey = "object_properties_" . $this->getId();
$properties = Cache::load($cacheKey);
if (!is_array($properties)) {
$properties = $this->getResource()->getProperties();
$elementCacheTag = $this->getCacheTag();
$cacheTags = array("object_properties" => "object_properties", $elementCacheTag => $elementCacheTag);
Cache::save($properties, $cacheKey, $cacheTags);
}
$this->setProperties($properties);
}
return $this->o_properties;
}
示例12: checkForRedirect
/**
* Checks for a suitable redirect
* @throws Exception
* @param bool $override
* @return void
*/
protected function checkForRedirect($override = false)
{
// not for admin requests
if (Tool::isFrontentRequestByAdmin()) {
return;
}
try {
$front = \Zend_Controller_Front::getInstance();
$config = Config::getSystemConfig();
// get current site if available
$sourceSite = null;
if (Site::isSiteRequest()) {
$sourceSite = Site::getCurrentSite();
}
$cacheKey = "system_route_redirect";
if (empty($this->redirects) && !($this->redirects = Cache::load($cacheKey))) {
$list = new Redirect\Listing();
$list->setOrder("DESC");
$list->setOrderKey("priority");
$this->redirects = $list->load();
Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998);
}
$requestScheme = $_SERVER['HTTPS'] == 'on' ? \Zend_Controller_Request_Http::SCHEME_HTTPS : \Zend_Controller_Request_Http::SCHEME_HTTP;
$matchRequestUri = $_SERVER["REQUEST_URI"];
$matchUrl = $requestScheme . "://" . $_SERVER["HTTP_HOST"] . $matchRequestUri;
foreach ($this->redirects as $redirect) {
$matchAgainst = $matchRequestUri;
if ($redirect->getSourceEntireUrl()) {
$matchAgainst = $matchUrl;
}
// if override is true the priority has to be 99 which means that overriding is ok
if (!$override || $override && $redirect->getPriority() == 99) {
if (@preg_match($redirect->getSource(), $matchAgainst, $matches)) {
// check for a site
if ($sourceSite) {
if ($sourceSite->getId() != $redirect->getSourceSite()) {
continue;
}
}
array_shift($matches);
$target = $redirect->getTarget();
if (is_numeric($target)) {
$d = Document::getById($target);
if ($d instanceof Document\Page || $d instanceof Document\Link || $d instanceof Document\Hardlink) {
$target = $d->getFullPath();
} else {
\Logger::error("Target of redirect no found (Document-ID: " . $target . ")!");
continue;
}
}
// replace escaped % signs so that they didn't have effects to vsprintf (PIMCORE-1215)
$target = str_replace("\\%", "###URLENCODE_PLACEHOLDER###", $target);
$url = vsprintf($target, $matches);
$url = str_replace("###URLENCODE_PLACEHOLDER###", "%", $url);
// support for pcre backreferences
$url = replace_pcre_backreferences($url, $matches);
if ($redirect->getTargetSite() && !preg_match("@http(s)?://@i", $url)) {
try {
$targetSite = Site::getById($redirect->getTargetSite());
// if the target site is specified and and the target-path is starting at root (not absolute to site)
// the root-path will be replaced so that the page can be shown
$url = preg_replace("@^" . $targetSite->getRootPath() . "/@", "/", $url);
$url = $requestScheme . "://" . $targetSite->getMainDomain() . $url;
} catch (\Exception $e) {
\Logger::error("Site with ID " . $redirect->getTargetSite() . " not found.");
continue;
}
} else {
if (!preg_match("@http(s)?://@i", $url) && $config->general->domain && $redirect->getSourceEntireUrl()) {
// prepend the host and scheme to avoid infinite loops when using "domain" redirects
$url = ($front->getRequest()->isSecure() ? "https" : "http") . "://" . $config->general->domain . $url;
}
}
// pass-through parameters if specified
$queryString = $_SERVER["QUERY_STRING"];
if ($redirect->getPassThroughParameters() && !empty($queryString)) {
$glue = "?";
if (strpos($url, "?")) {
$glue = "&";
}
$url .= $glue;
$url .= $queryString;
}
header($redirect->getHttpStatus());
header("Location: " . $url, true, $redirect->getStatusCode());
// log all redirects to the redirect log
\Pimcore\Log\Simple::log("redirect", Tool::getAnonymizedClientIp() . " \t Custom-Redirect ID: " . $redirect->getId() . " , Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
exit;
}
}
}
} catch (\Exception $e) {
// no suitable route found
}
//.........这里部分代码省略.........
示例13: dispatchLoopShutdown
/**
*
*/
public function dispatchLoopShutdown()
{
if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
return;
}
$cacheKey = "outputfilter_tagmngt";
$tags = Cache::load($cacheKey);
if (!is_array($tags)) {
$dir = Tool\Tag\Config::getWorkingDir();
$tags = array();
$files = scandir($dir);
foreach ($files as $file) {
if (strpos($file, ".xml")) {
$name = str_replace(".xml", "", $file);
$tags[] = Tool\Tag\Config::getByName($name);
}
}
Cache::save($tags, $cacheKey, array("tagmanagement"), null, 100);
}
if (empty($tags)) {
return;
}
$html = null;
$body = $this->getResponse()->getBody();
$requestParams = array_merge($_GET, $_POST);
foreach ($tags as $tag) {
$method = strtolower($tag->getHttpMethod());
$pattern = $tag->getUrlPattern();
$textPattern = $tag->getTextPattern();
// site check
if (\Site::isSiteRequest() && $tag->getSiteId()) {
if (\Site::getCurrentSite()->getId() != $tag->getSiteId()) {
continue;
}
} else {
if (!\Site::isSiteRequest() && $tag->getSiteId()) {
continue;
}
}
$requestPath = rtrim($this->getRequest()->getPathInfo(), "/");
if (($method == strtolower($this->getRequest()->getMethod()) || empty($method)) && (empty($pattern) || @preg_match($pattern, $requestPath)) && (empty($textPattern) || strpos($body, $textPattern) !== false)) {
$paramsValid = true;
foreach ($tag->getParams() as $param) {
if (!empty($param["name"])) {
if (!empty($param["value"])) {
if (!array_key_exists($param["name"], $requestParams) || $requestParams[$param["name"]] != $param["value"]) {
$paramsValid = false;
}
} else {
if (!array_key_exists($param["name"], $requestParams)) {
$paramsValid = false;
}
}
}
}
if (is_array($tag->getItems()) && $paramsValid) {
foreach ($tag->getItems() as $item) {
if (!empty($item["element"]) && !empty($item["code"]) && !empty($item["position"])) {
if (!$html) {
include_once "simple_html_dom.php";
$html = str_get_html($body);
}
if ($html) {
$element = $html->find($item["element"], 0);
if ($element) {
if ($item["position"] == "end") {
$element->innertext = $element->innertext . "\n\n" . $item["code"] . "\n\n";
} else {
// beginning
$element->innertext = "\n\n" . $item["code"] . "\n\n" . $element->innertext;
}
// we havve to reinitialize the html object, otherwise it causes problems with nested child selectors
$body = $html->save();
$html->clear();
unset($html);
$html = null;
}
}
}
}
}
}
}
if ($html && method_exists($html, "clear")) {
$html->clear();
unset($html);
}
$this->getResponse()->setBody($body);
}
示例14: getSupportedLocales
/**
* @return array|mixed
* @throws \Zend_Locale_Exception
*/
public static function getSupportedLocales()
{
// List of locales that are no longer part of CLDR
// this was also changed in the Zend Framework, but here we need to provide an appropriate alternative
// since this information isn't public in \Zend_Locale :-(
$aliases = ['az_AZ' => true, 'bs_BA' => true, 'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true, 'kk_KZ' => true, 'ks_IN' => true, 'mn_MN' => true, 'ms_BN' => true, 'ms_MY' => true, 'ms_SG' => true, 'pa_IN' => true, 'pa_PK' => true, 'shi_MA' => true, 'sr_BA' => true, 'sr_ME' => true, 'sr_RS' => true, 'sr_XK' => true, 'tg_TJ' => true, 'tzm_MA' => true, 'uz_AF' => true, 'uz_UZ' => true, 'vai_LR' => true, 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true];
$locale = \Zend_Locale::findLocale();
$cacheKey = "system_supported_locales_" . strtolower((string) $locale);
if (!($languageOptions = Cache::load($cacheKey))) {
// we use the locale here, because \Zend_Translate only supports locales not "languages"
$languages = \Zend_Locale::getLocaleList();
$languages = array_merge($languages, $aliases);
$languageOptions = array();
foreach ($languages as $code => $active) {
if ($active) {
$translation = \Zend_Locale::getTranslation($code, "language");
if (!$translation) {
$tmpLocale = new \Zend_Locale($code);
$lt = \Zend_Locale::getTranslation($tmpLocale->getLanguage(), "language");
$tt = \Zend_Locale::getTranslation($tmpLocale->getRegion(), "territory");
if ($lt && $tt) {
$translation = $lt . " (" . $tt . ")";
}
}
if (!$translation) {
$translation = $code;
}
$languageOptions[$code] = $translation;
}
}
asort($languageOptions);
Cache::save($languageOptions, $cacheKey, ["system"]);
}
return $languageOptions;
}
示例15: getValidTableColumns
/**
* @param string $table
* @param bool $cache
* @return array|mixed
*/
public function getValidTableColumns($table, $cache = true)
{
$cacheKey = self::CACHEKEY . $table;
if (\Zend_Registry::isRegistered($cacheKey)) {
$columns = \Zend_Registry::get($cacheKey);
} else {
$columns = Cache::load($cacheKey);
if (!$columns || !$cache) {
$columns = array();
$data = $this->db->fetchAll("SHOW COLUMNS FROM " . $table);
foreach ($data as $d) {
$columns[] = $d["Field"];
}
Cache::save($columns, $cacheKey, array("system", "resource"), null, 997);
}
\Zend_Registry::set($cacheKey, $columns);
}
return $columns;
}