Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceDetectorCache.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik;
  10. use Exception;
  11. /**
  12. * Caching class used for DeviceDetector caching
  13. *
  14. * Combines Piwik\CacheFile with an additional caching in static property
  15. *
  16. * Static caching speeds up multiple detections in one request, which is the case when sending bulk requests
  17. */
  18. class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\CacheInterface
  19. {
  20. protected static $staticCache = array();
  21. /**
  22. * Function to fetch a cache entry
  23. *
  24. * @param string $id The cache entry ID
  25. * @return array|bool False on error, or array the cache content
  26. */
  27. public function get($id)
  28. {
  29. if (empty($id)) {
  30. return false;
  31. }
  32. $id = $this->cleanupId($id);
  33. if (array_key_exists($id, self::$staticCache)) {
  34. return self::$staticCache[$id];
  35. }
  36. return parent::get($id);
  37. }
  38. /**
  39. * A function to store content a cache entry.
  40. *
  41. * @param string $id The cache entry ID
  42. * @param array $content The cache content
  43. * @throws \Exception
  44. * @return bool True if the entry was succesfully stored
  45. */
  46. public function set($id, $content)
  47. {
  48. if (empty($id)) {
  49. return false;
  50. }
  51. $id = $this->cleanupId($id);
  52. self::$staticCache[$id] = $content;
  53. return parent::set($id, $content);
  54. }
  55. }