\Drupal\strata\Capture\Classifier ClassificationRegistry

Remembers what each part of the ephemeral keyspace has been decided to be.

Rows are keyed by PATTERN, not by key. A site with two million cache entries under cache_render gets one row, and the volume is carried as counters on it. Storing a row per key would make the classification table larger than the thing it describes.

A human decision is never overwritten by a rule. Heuristics runs on every discovery pass and would otherwise re-derive its own answer over the top of a person's, silently, every cron. So a row whose source is human is left alone by everything except another human. That asymmetry is the whole reason this is stored rather than recomputed.

Summary

Methods
Properties
Constants
__construct
classify
captures
restores
isDecidedByHuman
all
undecided
statistics
observe
decide
forget
clear
reset
No public properties found
TABLE
No protected methods found
No protected properties found
No protected constants found
storedFor
write
resolved
database
No private constants found

Constant

TABLE

TABLE = 'strata_classification'

The table classifications live in.

Properties

$resolved

$resolved : array|null

Resolved patterns, keyed by pattern.

A discovery pass asks about the same pattern once per key it meets, so the answers are held for the pass rather than re-queried per key.

Type

array<string, Classification, source: string}>|null —

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

Methods

__construct()

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

Constructs a registry.

Parameters

\Drupal\Core\Database\Connection $database

The database.

Returns

mixed —

classify()

classify(string  $key) : \Drupal\strata\Capture\Classifier\Classification

What a key is classified as.

A stored pattern wins over a rule, and the most specific stored pattern wins over a broader one, so cache_render* decided by a human beats cache* derived by a rule.

Parameters

string $key

The key or namespace.

Returns

\Drupal\strata\Capture\Classifier\Classification —

The classification.

captures()

captures(string  $key) : bool

Whether a key is captured.

Parameters

string $key

The key or namespace.

Returns

bool —

TRUE when operations on this key are recorded.

restores()

restores(string  $key) : bool

Whether a key is written back by a restore.

Parameters

string $key

The key or namespace.

Returns

bool —

TRUE only when the key is known to be authoritative.

isDecidedByHuman()

isDecidedByHuman(string  $key) : bool

Whether a person decided this key's classification.

Parameters

string $key

The key or namespace.

Returns

bool —

TRUE when a stored row for it carries the human source.

all()

all() : array<string,array{classification: \Drupal\strata\Capture\Classifier\Classification, source: string}>

Every stored classification.

Returns

array

Pattern keyed to its decision.

undecided()

undecided(int  $limit = 50) : list<array<string,mixed>>

Patterns still waiting for a human decision, busiest first.

What the admin UI lists. Ordered by observed volume, because a pattern covering two million keys is the one worth deciding and a pattern covering three is not.

Parameters

int $limit

Most rows to return.

Returns

list> —

The rows.

statistics()

statistics() : array<string,array{patterns: int, keys: int, bytes: int}>

What the keyspace looks like, per classification.

Returns

array

Classification value keyed to its totals, with every classification present even at zero.

observe()

observe(string  $pattern, \Drupal\strata\Capture\Classifier\Classification  $classification, int  $keys, int  $bytes) : void

Records what a discovery pass observed under a pattern.

The classification is only set when the pattern is new. An existing row keeps whatever it says, because it may hold a decision, and the counters are replaced rather than added to because a pass measures the whole keyspace rather than the change since the last one.

Parameters

string $pattern

The pattern observed.

\Drupal\strata\Capture\Classifier\Classification $classification

What the heuristics made of it, used only for a pattern not seen before.

int $keys

Keys observed under it.

int $bytes

Bytes observed under it.

Returns

void —

decide()

decide(string  $pattern, \Drupal\strata\Capture\Classifier\Classification  $classification) : void

Records a person's decision about a pattern.

Parameters

string $pattern

The pattern.

\Drupal\strata\Capture\Classifier\Classification $classification

What they decided.

Returns

void —

forget()

forget(string  $pattern) : bool

Removes a stored classification, so the heuristics decide again.

Parameters

string $pattern

The pattern.

Returns

bool —

TRUE when a row was removed.

clear()

clear() : int

Drops every stored classification.

Returns

int —

How many rows were removed.

reset()

reset() : void

Forgets the resolved rows.

Called after a write, and by a long-running command between batches.

Returns

void —

storedFor()

storedFor(string  $key) : array{classification: \Drupal\strata\Capture\Classifier\Classification, source: string}|null

The most specific stored row covering a key.

Parameters

string $key

The key or namespace.

Returns

array{classification: \Drupal\strata\Capture\Classifier\Classification, source: string}|null —

The row, or NULL when nothing stored covers it.

write()

write(string  $pattern, \Drupal\strata\Capture\Classifier\Classification  $classification, string  $source, int  $keys, int  $bytes, bool  $keepCounters = false) : void

Writes one row.

Parameters

string $pattern

The pattern.

\Drupal\strata\Capture\Classifier\Classification $classification

The classification.

string $source

Either Heuristics::SOURCE or Heuristics::HUMAN.

int $keys

Keys observed.

int $bytes

Bytes observed.

bool $keepCounters

TRUE to leave the observed counters as they are, which a decision does: someone choosing a classification has not measured anything.

Returns

void —