Skip to content

Commit

Permalink
Make cache key base configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
madpilot78 committed Aug 17, 2024
1 parent cdb1977 commit 741594a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Auth/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class Session implements SessionInterface
{
private const string SESSION_CACHE_KEY = 'madpilot78:FreeBoxPHP:SessionToken';
private const string PERMISSIONS_CACHE_KEY = 'madpilot78:FreeBoxPHP:Permissions';
private const string SESSION_KEY = 'SessionToken';
private const string PERMISSIONS_KEY = 'Permissions';

public function __construct(
private AuthManagerInterface $authManager,
Expand All @@ -30,8 +30,8 @@ private function login(): string
{
$this->logger->debug('FreeBoxPHP starting Auth\Session::login()');

$session_token = $this->cache->get(self::SESSION_CACHE_KEY);
$permissions = $this->cache->get(self::PERMISSIONS_CACHE_KEY);
$session_token = $this->cache->get($this->config->cacheKeyBase . self::SESSION_KEY);
$permissions = $this->cache->get($this->config->cacheKeyBase . self::PERMISSIONS_KEY);

if (isset($session_token) && isset($permissions)) {
$this->authManager
Expand Down Expand Up @@ -68,8 +68,16 @@ private function login(): string
->setSessionToken($result['session_token'])
->setPermissions($result['permissions']);

$this->cache->set(self::SESSION_CACHE_KEY, $result['session_token'], $this->config->tokenTTL);
$this->cache->set(self::PERMISSIONS_CACHE_KEY, $result['permissions'], $this->config->tokenTTL);
$this->cache->set(
$this->config->cacheKeyBase . self::SESSION_KEY,
$result['session_token'],
$this->config->tokenTTL
);
$this->cache->set(
$this->config->cacheKeyBase . self::PERMISSIONS_KEY,
$result['permissions'],
$this->config->tokenTTL
);

$this->logger->debug('FreeBoxPHP ending Auth\Session::login() after query');

Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public const BoxType DEFAULT_BOX_TYPE = BoxType::Free;
public const int DEFAULT_TIMEOUT = 30;
public const string CERT_PATH = '/data';
public const string CACHE_KEY_BASE = 'madpilot78:FreeBoxPHP:';
public const int TOKEN_TTL = 7200;

public ?string $certFile;
Expand All @@ -41,6 +42,7 @@ public function __construct(
public ?ContainerInterface $container = null,
public int $timeout = self::DEFAULT_TIMEOUT,
public int $tokenTTL = self::TOKEN_TTL,
public string $cacheKeyBase = self::CACHE_KEY_BASE,
?CacheInterface $cache = null,
string $deviceName = self::DEFAULT_DEVICENAME,
?string $certFile = '',
Expand Down

0 comments on commit 741594a

Please sign in to comment.