final class RulePlanCache

Worker-lifetime LRU cache of compiled rule plans.

Plans are keyed by the normalized rule definition (string-only arrays). Plans are pure data — safe to cache across requests. A cached null-equivalent (un-cacheable) is represented by returning null from get(), not stored.

Bounded by $maxSize with LRU eviction. Typical apps have <1000 unique rules; the cap prevents pathological growth in apps that dynamically generate rules.

Constants

private DEFAULT_MAX_SIZE

Methods

static AttributePlan|null
get(array $rules)

Get a cached plan for the given rule array.

static void
put(array $rules, AttributePlan $plan)

Store a compiled plan in the cache.

static void
setMaxSize(int $size)

Set the maximum cache size. Intended for tests.

static void
flushState()

Flush all static state.

Details

at line 44
static AttributePlan|null get(array $rules)

Get a cached plan for the given rule array.

Returns null if the rules contain non-string elements (un-cacheable) or if no cached plan exists.

Parameters

array $rules

Return Value

AttributePlan|null

at line 66
static void put(array $rules, AttributePlan $plan)

Store a compiled plan in the cache.

Parameters

array $rules
AttributePlan $plan

Return Value

void

at line 97
static void setMaxSize(int $size)

Set the maximum cache size. Intended for tests.

Tests only. The cache size persists in a static property for the worker lifetime and affects every subsequent validation rule plan cache write.

Parameters

int $size

Return Value

void

at line 127
static void flushState()

Flush all static state.

Return Value

void