]> _ Git - cubist_matomo.git/commitdiff
wip #6015 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 22 Jun 2023 17:53:11 +0000 (19:53 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 22 Jun 2023 17:53:11 +0000 (19:53 +0200)
src/Reporting.php

index 32cbeb2a877a82dea5f3b9951099431977285f35..9c27e59b4738a8bca83cd1bfec2083def626f74e 100644 (file)
@@ -78,6 +78,11 @@ class Reporting {
      */
     protected $allSites = null;
 
+    /**
+     * @var int
+     */
+    protected $cacheDuration = 300;
+
     public function __construct(
         $baseUrl,
         $token,
@@ -95,6 +100,20 @@ class Reporting {
         $this->client = new Client(['base_uri' => $this->serverUrl]);
     }
 
+    /**
+     * @return int
+     */
+    public function getCacheDuration(): int {
+        return $this->cacheDuration;
+    }
+
+    /**
+     * @param int $cacheDuration
+     */
+    public function setCacheDuration(int $cacheDuration): void {
+        $this->cacheDuration = max(1, $cacheDuration);
+    }
+
     /**
      * Get API token
      *
@@ -358,7 +377,7 @@ class Reporting {
         $defaultOptions = ['query' => array_merge($default, $params)];
         $options = array_merge($defaultOptions, $options);
         $cacheKey = 'matomo_api_call' . hash('sha256', print_r($options, true));
-        return Cache::remember($cacheKey, 300, function () use ($options, $method) {
+        return Cache::remember($cacheKey, $this->getCacheDuration(), function () use ($options, $method) {
             try {
                 $response = $this->client->get('/', $options);
             } catch (RequestException $e) {