LruCachedFormix<T, E> class

A validator wrapper that caches multiple validation results using LRU eviction.

Maintains a cache of the most recently validated values and their results. When the cache reaches capacity, the least recently used entry is evicted.

final validator = StringRules.email(error: 'Invalid').lruCached(maxSize: 10);

// Each unique value is cached
validator.validate('a@example.com'); // Computed, cached
validator.validate('b@example.com'); // Computed, cached
validator.validate('a@example.com'); // Cache hit!

This is particularly useful for:

  • Autocomplete/search fields with multiple recent values
  • Dropdowns or select fields where users switch between options
  • Any scenario where multiple distinct values are validated repeatedly
Inheritance
Available extensions

Constructors

LruCachedFormix(Formix<T, E> _inner, {int maxSize = 10})
Creates an LRU cached wrapper around inner.

Properties

cachedValues List<T>
Returns all currently cached values in access order (oldest first).
no setter
hashCode int
The hash code for this object.
no setterinherited
inner Formix<T, E>
The underlying validator being cached.
no setter
maxSize int
The maximum number of cached results.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
The current number of cached results.
no setter

Methods

andThen(Formix<T, E> next) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Chains this validator with next, running next only if this passes.
cached() CachedFormix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Wraps this validator with single-value caching.
clear() → void
Clears all cached results.
containsKey(T value) bool
Returns true if the value is in the cache.
lazy() LazyFormix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Creates a lazy validator that defers instantiation until first use.
lruCached({int maxSize = 10}) LruCachedFormix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Wraps this validator with LRU (Least Recently Used) caching.
mapError<E2>(E2 mapper(E error)) Formix<T, E2>

Available on Formix<T, E>, provided by the FormixExtensions extension

Maps errors from type E to type E2.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optional({bool isEmpty(T value)?}) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Makes this validator optional - skips validation when empty.
peek(T value) ValidationResult<T, E>?
Returns the cached result for value, or null if not cached.
recover(T onError(List<E> errors)) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Recovers from validation errors with a default value.
remove(T value) bool
Removes a specific value from the cache.
tap({void onValid(T value)?, void onInvalid(List<E> errors)?}) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Applies side effects without affecting validation.
toString() String
A string representation of this object.
inherited
validate(T value) ValidationResult<T, E>
Validates value and returns a ValidationResult.
override
when(bool condition(T value)) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Conditionally applies this validator based on condition.
whenNot(bool condition(T value)) Formix<T, E>

Available on Formix<T, E>, provided by the FormixExtensions extension

Conditionally skips this validator based on condition.
withMessageFormatter(ErrorMessageFormatter<E> formatter) Formix<T, String>

Available on Formix<T, E>, provided by the FormixExtensions extension

Maps errors to user-facing messages using formatter.

Operators

operator ==(Object other) bool
The equality operator.
inherited