/** * 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); }
/** * 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); }
public function testGetAllCachedSiteUrls_ShouldReadFromTheCacheFile() { $urlsToFake = array(1 => 'Whatever'); $cache = new CacheFile('tracker', 600); $cache->set('allSiteUrlsPerSite', $urlsToFake); $actual = $this->siteUrls->getAllCachedSiteUrls(); $this->assertEquals($urlsToFake, $actual); }
private function cacheResult($action, $query, $result) { $cacheKey = $this->getCacheKey($action, $query); $this->cache->set($cacheKey, $result); }