OAuth2 client credentials flow with cache

This commit is contained in:
2024-11-10 23:32:27 +01:00
parent 255d0189ab
commit fde083f36f
4 changed files with 112 additions and 46 deletions

View File

@@ -20,7 +20,7 @@ use CloudObjects\SDK\AccountGateway\AccountContext;
/**
* The ObjectRetriever provides access to objects on CloudObjects.
*/
class ObjectRetriever {
class ObjectRetriever implements CustomCacheAndLogInterface {
use LoggerAwareTrait;
@@ -107,19 +107,27 @@ class ObjectRetriever {
$this->client = new Client($options);
}
private function logInfoWithTime($message, $ts) {
public function logInfoWithTime($message, $ts) {
if (isset($this->logger))
$this->logger->info($message, [ 'elapsed_ms' => round((microtime(true) - $ts) * 1000) ]);
}
private function getFromCache($id) {
return (isset($this->cache) && $this->cache->contains($this->options['cache_prefix'].$id))
? $this->cache->fetch($this->options['cache_prefix'].$id) : null;
? $this->cache->fetch($this->options['cache_prefix'].$this->options['auth_ns'].'/'.$id) : null;
}
private function putIntoCache($id, $data, $ttl) {
if (isset($this->cache))
$this->cache->save($this->options['cache_prefix'].$id, $data, $ttl);
$this->cache->save($this->options['cache_prefix'].$this->options['auth_ns'].'/'.$id, $data, $ttl);
}
public function getFromCacheCustom($id) {
return $this->getFromCache('custom/'.$id);
}
public function putIntoCacheCustom($id, $data, $ttl) {
$this->putIntoCache('custom/'.$id, $data, $ttl);
}
/**