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:
authorsgiehl <stefan@piwik.org>2014-05-31 22:50:25 +0400
committersgiehl <stefan@piwik.org>2014-05-31 22:50:25 +0400
commit0d7b51944e9b1c18859dcb99ed6397859ca17e07 (patch)
tree7a4c71e3ab1078848436f1382b21c63de8977fde /core/DeviceDetectorCache.php
parenteaf1036670082fcedeae42d03624c9312a5db271 (diff)
added special DeviceDetectorCache class used for caching DeviceDetector. This cache combines file and static caching to speed up detections as much as possible
Diffstat (limited to 'core/DeviceDetectorCache.php')
-rw-r--r--core/DeviceDetectorCache.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/core/DeviceDetectorCache.php b/core/DeviceDetectorCache.php
new file mode 100644
index 0000000000..744560df92
--- /dev/null
+++ b/core/DeviceDetectorCache.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik;
+
+use Exception;
+
+/**
+ * Caching class used for DeviceDetector caching
+ *
+ * Combines Piwik\CacheFile with an additional caching in static property
+ *
+ * Static caching speeds up multiple detections in one request, which is mostly the case when importing logs
+ */
+class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\CacheInterface
+{
+ protected static $staticCache = array();
+
+ /**
+ * Function to fetch a cache entry
+ *
+ * @param string $id The cache entry ID
+ * @return array|bool False on error, or array the cache content
+ */
+ public function get($id)
+ {
+ if (empty($id)) {
+ return false;
+ }
+ $id = $this->cleanupId($id);
+
+ if (array_key_exists($id, self::$staticCache)) {
+ return self::$staticCache[$id];
+ }
+
+ return parent::get($id);
+ }
+
+
+ /**
+ * 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);
+ }
+}