Pimcore\Cache::load PHP Метод

load() публичный статический Метод

Returns the content of the requested cache entry
public static load ( string $key, $doNotTestCacheValidity = false ) : mixed
$key string
Результат mixed
    public static function load($key, $doNotTestCacheValidity = false)
    {
        if (!self::$enabled) {
            Logger::debug("Key " . $key . " doesn't exist in cache (deactivated)");
            return;
        }
        if ($cache = self::getInstance()) {
            $key = self::$cachePrefix . $key;
            $data = $cache->load($key, $doNotTestCacheValidity);
            $data = unserialize($data);
            if (is_object($data)) {
                $data->____pimcore_cache_item__ = $key;
            }
            if ($data !== false) {
                Logger::debug("Successfully got data for key " . $key . " from cache");
            } else {
                Logger::debug("Key " . $key . " doesn't exist in cache");
            }
            return $data;
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * @return array|mixed
  */
 public function getAllTranslations()
 {
     $cacheKey = static::getTableName() . "_data";
     if (!($translations = Cache::load($cacheKey))) {
         $itemClass = static::getItemClass();
         $translations = [];
         $select = $this->db->select();
         // create base
         $select->from([static::getTableName()]);
         if ($this->onCreateQueryCallback) {
             $closure = $this->onCreateQueryCallback;
             $closure($select);
         }
         $translationsData = $this->db->fetchAll($select);
         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, ["translator", "translate"], 999);
     }
     return $translations;
 }
All Usage Examples Of Pimcore\Cache::load