CacheTokenStore
in package
implements
TokenStoreInterface
FinalYes
Keeps tokens in a ReactPHP or PSR-16 cache — Redis, for instance.
Tokens are stored with no expiry of their own. Give this a cache that will
not evict them: a dedicated Redis database with no maxmemory eviction, not
the one the part cache shares.
Tags
Table of Contents
Interfaces
- TokenStoreInterface
- Where users' OAuth2 tokens are kept between restarts.
Properties
Methods
- __construct() : mixed
- delete() : PromiseInterface<string|int, bool>
- get() : PromiseInterface<string|int, ?AccessToken>
- set() : PromiseInterface<string|int, bool>
- call() : PromiseInterface
- Runs a cache call, which a ReactPHP cache answers with a promise and a PSR-16 cache answers directly, or by throwing.
- key() : string
- Encoded, because PSR-16 reserves `{}()/\@:` in keys and a store key may well contain `:`.
Properties
$cache
private
CacheInterface|CacheInterface
$cache
$prefix
private
string
$prefix
= 'discordphp.oauth2.token.'
Methods
__construct()
public
__construct(CacheInterface|CacheInterface $cache[, string $prefix = 'discordphp.oauth2.token.' ]) : mixed
Parameters
- $cache : CacheInterface|CacheInterface
-
Where to keep the tokens.
- $prefix : string = 'discordphp.oauth2.token.'
-
Prepended to every key.
delete()
public
delete(string $key) : PromiseInterface<string|int, bool>
Parameters
- $key : string
-
What the token was stored under.
Return values
PromiseInterface<string|int, bool>get()
public
get(string $key) : PromiseInterface<string|int, ?AccessToken>
Parameters
- $key : string
-
What the token was stored under.
Return values
PromiseInterface<string|int, ?AccessToken> —The token, or null if none is stored.
set()
public
set(string $key, AccessToken $token) : PromiseInterface<string|int, bool>
Parameters
- $key : string
-
What to store the token under.
- $token : AccessToken
-
The token.
Return values
PromiseInterface<string|int, bool>call()
Runs a cache call, which a ReactPHP cache answers with a promise and a PSR-16 cache answers directly, or by throwing.
private
call(callable $call) : PromiseInterface
Parameters
- $call : callable
Return values
PromiseInterfacekey()
Encoded, because PSR-16 reserves `{}()/\@:` in keys and a store key may well contain `:`.
private
key(string $key) : string
Parameters
- $key : string