DiscordPHP-MTG Documentation

SearchCache
in package

FinalYes

Short-lived state behind a message's components — a search's filters, an opened booster's cards — under an id short enough for a `custom_id`.

A component's custom_id holds at most 100 characters, too few for a set of search filters, so a results page carries card:page:<id>:<page> and the filters wait here. Entries expire after TTL and the oldest go first past LIMIT; a click on an expired one is told to search again. Kept in memory: a restart forgets them, as it would a conversation.

Tags
since
1.1.0

Table of Contents

Constants

LIMIT  : int = 1000
Entries kept at most.
TTL  : int = 3600
Seconds an entry is kept after it was last used.

Properties

$entries  : array<string, array{0: int, 1: array}>
Entries by id, least recently used first.

Methods

get()  : array<string|int, mixed>|null
Gets state back, renewing it.
put()  : string
Stores state and returns its id.
prune()  : void
Drops expired entries, then the oldest past the limit.

Constants

TTL

Seconds an entry is kept after it was last used.

public int TTL = 3600

Properties

$entries

Entries by id, least recently used first.

private array<string, array{0: int, 1: array}> $entries = []

Methods

get()

Gets state back, renewing it.

public get(string $id) : array<string|int, mixed>|null
Parameters
$id : string
Return values
array<string|int, mixed>|null —

Null once it has expired.

put()

Stores state and returns its id.

public put(array<string|int, mixed> $state) : string
Parameters
$state : array<string|int, mixed>

Anything serializable.

Return values
string —

An 8-character id.

prune()

Drops expired entries, then the oldest past the limit.

private prune() : void
On this page

Search results