Skip to content

Commit 756d3a2

Browse files
author
Dima Novoseltsev
committed
QUASAR-2638 - caching access token
1 parent 0f9a7af commit 756d3a2

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/authfilter/Module.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,7 @@ public function init()
8282
throw new InvalidConfigException('Auth server url not configured');
8383
}
8484
$this->setHttpClient(new $this->httpClientClass);
85-
86-
if ($this->cache !== false && $this->cache !== null) {
87-
try {
88-
$this->cache = Instance::ensure(
89-
$this->cache,
90-
'yii\caching\CacheInterface'
91-
);
92-
} catch (InvalidConfigException $e) {
93-
Yii::warning(
94-
'Unable to use cache for URL manager: ' . $e->getMessage()
95-
);
96-
}
97-
}
85+
$this->initCacheInstance();
9886
}
9987

10088
/**
@@ -204,6 +192,18 @@ public function validateRequest(Request $request)
204192
return $afterValidate;
205193
}
206194

195+
private function initCacheInstance()
196+
{
197+
if ($this->cache !== false && $this->cache !== null && !($this->cache instanceof CacheInterface)) {
198+
try {
199+
$this->cache = Instance::ensure($this->cache, 'yii\caching\CacheInterface');
200+
} catch (InvalidConfigException $e) {
201+
Yii::warning('Unable to use cache for URL manager: ' . $e->getMessage());
202+
}
203+
}
204+
}
205+
206+
207207
/**
208208
* @param string $username
209209
* @param string $password
@@ -222,6 +222,7 @@ public function requestAccessToken(
222222
$grantType = 'password',
223223
$cacheTtl = 0
224224
) {
225+
$this->initCacheInstance();
225226
if ($this->testMode) {
226227
return TestHelper::getTokenInfo($rawResponse);
227228
}

0 commit comments

Comments
 (0)