\Drupal\strata\Capture\Classifier DatabaseKeyspaceSource

Reads the ephemeral keyspace out of the database.

The source every site has. Drupal's default cache, key-value and expirable backends are tables, so a site with no Redis still has a describable keyspace and still gets a classification pass. When strata_redis is installed its own source is added alongside this one rather than replacing it, because a site commonly keeps some bins in the database and moves only the hot ones.

Sizes come from the stored value's length, which is a lower bound on what the entry costs: it excludes the key, the expiry and the tags. That is the right direction to be wrong in for a number used to rank what needs a decision.

Summary

Methods
Properties
Constants
__construct
id
isAvailable
keys
No public properties found
SHAPES
No protected methods found
No protected properties found
No protected constants found
tables
fromTable
database
No private constants found

Constant

SHAPES

SHAPES = ['cache_' => ['key' => 'cid', 'value' => 'data'], 'key_value_expire' => ['key' => 'name', 'value' => 'value'], 'key_value' => ['key' => 'name', 'value' => 'value'], 'queue' => ['key' => 'name', 'value' => 'data'], 'semaphore' => ['key' => 'name', 'value' => 'value'], 'flood' => ['key' => 'event', 'value' => 'identifier'], 'sessions' => ['key' => 'sid', 'value' => 'session']] : array<string, array{key: string, value: string}>

Table prefixes that hold ephemeral entries, with the column naming each entry.

Properties

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

Methods

__construct()

__construct(\Drupal\Core\Database\Connection  $database) : mixed

Constructs a source.

Parameters

\Drupal\Core\Database\Connection $database

The connection to read.

Returns

mixed —

id()

id() : string

A short identifier, used to name this source in a problem report.

Returns

string —

For example "redis" or "database".

isAvailable()

isAvailable() : bool

Whether this source can be read right now.

Returns

bool —

FALSE when the backend it reads is absent or unreachable, so discovery can skip it without treating that as a fault.

keys()

keys(int  $limit) : \Traversable<string,int>

The keys this source holds, with their sizes.

Parameters

int $limit

Most keys to return.

Returns

\Traversable

Key name keyed to its size in bytes. A source that cannot measure a size yields zero rather than guessing, and the byte totals are then understood to be a lower bound.

tables()

tables() : array<string,array{key: string, value: string}>

Tables on this connection that hold ephemeral entries.

Returns

array

Table name keyed to the shape it uses.

fromTable()

fromTable(string  $table, array{key: string, value: string}  $shape, int  $limit, int  $remaining) : \Generator<string,int>

Reads keys out of one table.

Parameters

string $table

The table name.

array{key: string, value: string} $shape

Which columns hold the key and the value.

int $limit

Most rows to read.

int $remaining

Decremented as rows are yielded, so the caller's overall bound is respected.

Returns

\Generator

Key name keyed to its size in bytes.