예제 #1
0
 /**
  * @return array names of plugins that have been loaded
  */
 public function loadTrackerPlugins()
 {
     $cacheId = 'PluginsTracker';
     $cache = Cache::getEagerCache();
     if ($cache->contains($cacheId)) {
         $pluginsTracker = $cache->fetch($cacheId);
     } else {
         $this->unloadPlugins();
         $this->loadActivatedPlugins();
         $pluginsTracker = array();
         foreach ($this->loadedPlugins as $pluginName => $plugin) {
             if ($this->isTrackerPlugin($plugin)) {
                 $pluginsTracker[] = $pluginName;
             }
         }
         if (!empty($pluginsTracker)) {
             $cache->save($cacheId, $pluginsTracker);
         }
     }
     if (empty($pluginsTracker)) {
         $this->unloadPlugins();
         return array();
     }
     $pluginsTracker = array_diff($pluginsTracker, $this->getTrackerPluginsNotToLoad());
     $this->doNotLoadAlwaysActivatedPlugins();
     $this->loadPlugins($pluginsTracker);
     // we could simply unload all plugins first before loading plugins but this way it is much faster
     // since we won't have to create each plugin again and we won't have to parse each plugin metadata file
     // again etc
     $this->makeSureOnlyActivatedPluginsAreLoaded();
     return $pluginsTracker;
 }
예제 #2
0
 /**
  * Returns list of search engines by URL
  *
  * @return array  Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) )
  */
 public function getDefinitions()
 {
     $cache = Cache::getEagerCache();
     $cacheId = 'SearchEngine-' . self::OPTION_STORAGE_NAME;
     if ($cache->contains($cacheId)) {
         $list = $cache->fetch($cacheId);
     } else {
         $list = $this->loadDefinitions();
         $cache->save($cacheId, $list);
     }
     return $list;
 }
예제 #3
0
 private function getSpammerListFromCache()
 {
     $cache = Cache::getEagerCache();
     $cacheId = 'ReferrerSpamFilter-' . self::OPTION_STORAGE_NAME;
     if ($cache->contains($cacheId)) {
         $list = $cache->fetch($cacheId);
     } else {
         $list = $this->loadSpammerList();
         $cache->save($cacheId, $list);
     }
     return $list;
 }
예제 #4
0
 public function test_getEagerCache_shouldPersistOnceEventWasTriggered()
 {
     $storageId = 'eagercache-test-ui';
     $cache = Cache::getEagerCache();
     $cache->save('test', 'mycontent');
     // make sure something was changed, otherwise it won't save anything
     /** @var Cache\Backend $backend */
     $backend = StaticContainer::get('Piwik\\Cache\\Backend');
     $this->assertFalse($backend->doContains($storageId));
     Piwik::postEvent('Request.dispatch.end');
     // should trigger save
     $this->assertTrue($backend->doContains($storageId));
 }
예제 #5
0
 /**
  * Setup the database and create the base tables for all tests
  */
 public function setUp()
 {
     parent::setUp();
     static::$fixture->extraDefinitions = array_merge(static::provideContainerConfigBeforeClass(), $this->provideContainerConfig());
     static::$fixture->createEnvironmentInstance();
     Db::createDatabaseObject();
     Fixture::loadAllPlugins(new TestingEnvironmentVariables(), get_class($this), self::$fixture->extraPluginsToLoad);
     Access::getInstance()->setSuperUserAccess(true);
     if (!empty(self::$tableData)) {
         self::restoreDbTables(self::$tableData);
     }
     PiwikCache::getEagerCache()->flushAll();
     PiwikCache::getTransientCache()->flushAll();
     MenuAbstract::clearMenus();
 }
예제 #6
0
 private function getSpammerListFromCache()
 {
     $cache = Cache::getEagerCache();
     $cacheId = 'ReferrerSpamFilter-' . self::OPTION_STORAGE_NAME;
     if ($cache->contains($cacheId)) {
         $list = $cache->fetch($cacheId);
     } else {
         $list = $this->loadSpammerList();
         $cache->save($cacheId, $list);
     }
     if (!is_array($list)) {
         Common::printDebug('Warning: could not read list of spammers from cache.');
         return array();
     }
     return $list;
 }
예제 #7
0
 public function test_flushAll_shouldActuallyFlushAllCaches()
 {
     $cache1 = Cache::getTransientCache();
     $cache2 = Cache::getLazyCache();
     $cache3 = Cache::getEagerCache();
     $cache1->save('test1', 'content');
     $cache2->save('test2', 'content');
     $cache3->save('test3', 'content');
     $this->assertTrue($cache1->contains('test1'));
     $this->assertTrue($cache2->contains('test2'));
     $this->assertTrue($cache3->contains('test3'));
     Cache::flushAll();
     $this->assertFalse($cache1->contains('test1'));
     $this->assertFalse($cache2->contains('test2'));
     $this->assertFalse($cache3->contains('test3'));
 }
예제 #8
0
 private static function getMapOfModuleActionsToReport()
 {
     $cacheId = CacheId::pluginAware('ReportFactoryMap');
     $cache = PiwikCache::getEagerCache();
     if ($cache->contains($cacheId)) {
         $mapApiToReport = $cache->fetch($cacheId);
     } else {
         $reports = new static();
         $reports = $reports->getAllReports();
         $mapApiToReport = array();
         foreach ($reports as $report) {
             $key = $report->getModule() . '.' . ucfirst($report->getAction());
             if (isset($mapApiToReport[$key]) && $report->getParameters()) {
                 // sometimes there are multiple reports with same module/action but different parameters.
                 // we might pick the "wrong" one. At some point we should compare all parameters and if there is
                 // a report which parameters mach $_REQUEST then we should prefer that report
                 continue;
             }
             $mapApiToReport[$key] = get_class($report);
         }
         $cache->save($cacheId, $mapApiToReport);
     }
     return $mapApiToReport;
 }
예제 #9
0
 public function __construct($ttl = 300)
 {
     $this->ttl = (int) $ttl;
     $this->cache = PiwikCache::getEagerCache();
 }
예제 #10
0
 public function clearInMemoryCaches()
 {
     Archive::clearStaticCache();
     DataTableManager::getInstance()->deleteAll();
     Option::clearCache();
     Site::clearCache();
     Cache::deleteTrackerCache();
     PiwikCache::getTransientCache()->flushAll();
     PiwikCache::getEagerCache()->flushAll();
     PiwikCache::getLazyCache()->flushAll();
     ArchiveTableCreator::clear();
     \Piwik\Plugins\ScheduledReports\API::$cache = array();
     Singleton::clearAll();
     PluginsArchiver::$archivers = array();
     $_GET = $_REQUEST = array();
     Translate::reset();
     self::getConfig()->Plugins;
     // make sure Plugins exists in a config object for next tests that use Plugin\Manager
     // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object
 }
예제 #11
0
파일: Report.php 프로젝트: bossrabbit/piwik
 private static function getMapOfModuleActionsToReport()
 {
     $cacheId = CacheId::pluginAware('ReportFactoryMap');
     $cache = Cache::getEagerCache();
     if ($cache->contains($cacheId)) {
         $mapApiToReport = $cache->fetch($cacheId);
     } else {
         $reports = self::getAllReports();
         $mapApiToReport = array();
         foreach ($reports as $report) {
             $key = $report->getModule() . '.' . ucfirst($report->getAction());
             $mapApiToReport[$key] = get_class($report);
         }
         $cache->save($cacheId, $mapApiToReport);
     }
     return $mapApiToReport;
 }
예제 #12
0
파일: API.php 프로젝트: bossrabbit/piwik
 private function loadAvailableLanguages()
 {
     if (!is_null($this->availableLanguageNames)) {
         return;
     }
     $cacheId = 'availableLanguages';
     $cache = PiwikCache::getEagerCache();
     if ($cache->contains($cacheId)) {
         $languagesInfo = $cache->fetch($cacheId);
     } else {
         $filenames = $this->getAvailableLanguages();
         $languagesInfo = array();
         foreach ($filenames as $filename) {
             $data = file_get_contents(PIWIK_INCLUDE_PATH . "/lang/{$filename}.json");
             $translations = json_decode($data, true);
             $languagesInfo[] = array('code' => $filename, 'name' => $translations['General']['OriginalLanguageName'], 'english_name' => $translations['General']['EnglishLanguageName']);
         }
         $cache->save($cacheId, $languagesInfo);
     }
     $this->availableLanguageNames = $languagesInfo;
 }
예제 #13
0
파일: Plugin.php 프로젝트: nuxwin/piwik
 private function createCacheIfNeeded()
 {
     if (is_null($this->cache)) {
         $this->cache = Cache::getEagerCache();
     }
 }
예제 #14
0
 private static function buildCache()
 {
     return PiwikCache::getEagerCache();
 }
예제 #15
0
파일: API.php 프로젝트: dorelljames/piwik
 private function loadAvailableLanguages()
 {
     if (!is_null($this->availableLanguageNames)) {
         return;
     }
     $cacheId = 'availableLanguages';
     $cache = PiwikCache::getEagerCache();
     if ($cache->contains($cacheId)) {
         $languagesInfo = $cache->fetch($cacheId);
     } else {
         $languages = $this->getAvailableLanguages();
         $languagesInfo = array();
         foreach ($languages as $languageCode) {
             $data = @file_get_contents(PIWIK_INCLUDE_PATH . "/plugins/Intl/lang/{$languageCode}.json");
             // Skip languages not having Intl translations
             if (empty($data)) {
                 continue;
             }
             $translations = json_decode($data, true);
             $languagesInfo[] = array('code' => $languageCode, 'name' => $translations['Intl']['OriginalLanguageName'], 'english_name' => $translations['Intl']['EnglishLanguageName']);
         }
         $cache->save($cacheId, $languagesInfo);
     }
     $this->availableLanguageNames = $languagesInfo;
 }
 private function getCache()
 {
     return PiwikCache::getEagerCache();
 }
예제 #17
0
 private function getCacheForTrackerPlugins()
 {
     return PiwikCache::getEagerCache();
 }