validate method
Validates value and returns a ValidationResult.
Returns Valid if the value passes validation, or Invalid/InvalidAll if it fails.
Implementation
@override
ValidationResult<T, E> validate(T value) {
// Check for cache hit
if (_cache.containsKey(value)) {
// Move to end (most recently used)
_accessOrder.remove(value);
_accessOrder.add(value);
return _cache[value]!;
}
// Compute result
final result = _inner.validate(value);
// Evict oldest if at capacity
if (_cache.length >= _maxSize) {
final oldest = _accessOrder.removeAt(0);
_cache.remove(oldest);
}
// Cache the result
_cache[value] = result;
_accessOrder.add(value);
return result;
}