DiscordPHP Documentation

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
since
10.59.0

Table of Contents

Interfaces

TokenStoreInterface
Where users' OAuth2 tokens are kept between restarts.

Properties

$cache  : CacheInterface|CacheInterface
$prefix  : string

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

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
PromiseInterface

key()

Encoded, because PSR-16 reserves `{}()/\@:` in keys and a store key may well contain `:`.

private key(string $key) : string
Parameters
$key : string
Return values
string
On this page

Search results