From 0a9a39884bbd73ccebbe2b2ed61c04d384ad9be6 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 11 Aug 2022 18:14:37 +0200 Subject: [PATCH] Add optional cache lifetime option * add optional cache lifetime option for file cache type --- src/Base/MicrosoftConfiguration.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Base/MicrosoftConfiguration.php b/src/Base/MicrosoftConfiguration.php index 5a2836c1..10d1485b 100644 --- a/src/Base/MicrosoftConfiguration.php +++ b/src/Base/MicrosoftConfiguration.php @@ -74,8 +74,16 @@ public function __construct($options = []) throw new UnexpectedValueException('Missing file path'); } + $lifetime=self::CACHE_LIFETIME; + if (isset($options['cache']['lifetime'])) { + if(!is_int($options['cache']['lifetime']) || $options['cache']['lifetime'] < 0) { + throw new UnexpectedValueException('Invalid cache lifetime'); + } + $lifetime= $options['cache']['lifetime']; + } + $directory = $options['cache']['path']; - $this->cache = new FilesystemAdapter(self::CACHE_NAMESPACE, self::CACHE_LIFETIME, $directory); + $this->cache = new FilesystemAdapter(self::CACHE_NAMESPACE, $lifetime, $directory); } if ($options['cache']['type'] === 'redis') { @@ -294,4 +302,4 @@ private function getJwkFromJson($json) { $data = json_decode($json, true); return JWK::parseKeySet($data); } -} \ No newline at end of file +}