/** * A function to store content a cache entry. * * @param string $id The cache entry ID * @param array $content The cache content * @throws \Exception * @return bool True if the entry was succesfully stored */ public function set($id, $content) { if (empty($id)) { return false; } $id = $this->cleanupId($id); self::$staticCache[$id] = $content; return parent::set($id, $content); }
/** * @return CacheFile */ private static function getStorage() { if (is_null(self::$storage)) { self::$storage = new CacheFile('tracker', 43200); self::$storage->addOnDeleteCallback(function () { PersistentCache::_reset(); }); } return self::$storage; }
/** * Load translations for loaded plugins * * @param bool|string $language Optional language code */ public function loadPluginTranslations($language = false) { if (empty($language)) { $language = Translate::getLanguageToLoad(); } $cache = new CacheFile('tracker', 43200); // ttl=12hours $cacheKey = 'PluginTranslations'; if (!empty($language)) { $cacheKey .= '-' . trim($language); } if (!empty($this->loadedPlugins)) { // makes sure to create a translation in case loaded plugins change (ie Tests vs Tracker vs UI etc) $cacheKey .= '-' . md5(implode('', $this->getLoadedPluginsName())); } $translations = $cache->get($cacheKey); if (!empty($translations) && is_array($translations) && !Development::isEnabled()) { Translate::mergeTranslationArray($translations); return; } $translations = array(); $pluginNames = self::getAllPluginsNames(); foreach ($pluginNames as $pluginName) { if ($this->isPluginLoaded($pluginName) || $this->isPluginBundledWithCore($pluginName)) { $this->loadTranslation($pluginName, $language); if (isset($GLOBALS['Piwik_translations'][$pluginName])) { $translations[$pluginName] = $GLOBALS['Piwik_translations'][$pluginName]; } } } $cache->set($cacheKey, $translations); }
private function assertValueInCache($value) { $cache = new CacheFile('tracker', 600); $siteUrls = $cache->get('allSiteUrlsPerSite'); $this->assertEquals($value, $siteUrls); }
private function cacheResult($action, $query, $result) { $cacheKey = $this->getCacheKey($action, $query); $this->cache->set($cacheKey, $result); }