From 4bad38868a2e4952139caa90d27fe580deee5a0e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 22 Jun 2023 19:53:11 +0200 Subject: [PATCH] wip #6015 @0.25 --- src/Reporting.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Reporting.php b/src/Reporting.php index 32cbeb2..9c27e59 100644 --- a/src/Reporting.php +++ b/src/Reporting.php @@ -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) { -- 2.39.5