Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-11-27 06:43:37 +0300
committerThomas Steur <thomas.steur@googlemail.com>2014-11-27 06:43:37 +0300
commita2d438198f171e0844318e1bec45c0bc7573e1a2 (patch)
tree0cbd74b1fd19d0712695982de2b2389c3d71d224 /core/Tracker/SettingsStorage.php
parenta3d51aa45295105752f16e252a8e11eb59002d8e (diff)
refs #6728 automatically cache settings in tracker cache if used in tracker mode.
As soon as a setting is used in tracker mode we will cache it now making it much easier for developers to use settings in tracker mode and we will no longer query the database on each tracking request if a setting is requested apart from cache creation. Refactored the settings API under the hood to make this possible. The classes were doing things they were not supposed to do. For instance settings class also took care of storage which it should not and settings class took care of many validation things that should be done in a setting class. I cleaned up that code and it is also much better testable now.
Diffstat (limited to 'core/Tracker/SettingsStorage.php')
-rw-r--r--core/Tracker/SettingsStorage.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/core/Tracker/SettingsStorage.php b/core/Tracker/SettingsStorage.php
new file mode 100644
index 0000000000..6c54b1b993
--- /dev/null
+++ b/core/Tracker/SettingsStorage.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik\Tracker;
+
+use Piwik\Settings\Storage;
+use Piwik\Tracker;
+
+/**
+ * Loads settings from tracker cache instead of database. If not yet present in tracker cache will cache it.
+ */
+class SettingsStorage extends Storage
+{
+
+ protected function loadSettings()
+ {
+ $trackerCache = Cache::getCacheGeneral();
+ $settings = null;
+
+ if (array_key_exists('settingsStorage', $trackerCache)) {
+ $allSettings = $trackerCache['settingsStorage'];
+
+ if (is_array($allSettings) && array_key_exists($this->getOptionKey(), $allSettings)) {
+ $settings = $allSettings[$this->getOptionKey()];
+ }
+ } else {
+ $trackerCache['settingsStorage'] = array();
+ }
+
+ if (is_null($settings)) {
+ $settings = parent::loadSettings();
+
+ $trackerCache['settingsStorage'][$this->getOptionKey()] = $settings;
+ Cache::setCacheGeneral($trackerCache);
+ }
+
+ return $settings;
+ }
+
+ public function save()
+ {
+ parent::save();
+ self::clearCache();
+ }
+
+ public static function clearCache()
+ {
+ Cache::clearCacheGeneral();
+ }
+
+}