OAuth2 client credentials flow with cache
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user