LruPlugin class
LRU Plugin - Least Recently Used cache management.
Bundles LRU conditions and hooks for easy installation.
Features
- Touch hook: Updates last_accessed on reads
- Init hook: Sets initial LRU metadata on writes
- Recently accessed condition: Checks if entry was accessed within threshold
- Frequently accessed condition: Checks if access count meets minimum
Example
final engine = HiEngine();
LruPlugin().install(engine);
// With access count tracking
LruPlugin(
trackAccessCount: true,
readEvents: ['read', 'get'],
).install(engine);
Constructors
-
LruPlugin({String metaKey = 'meta', String lastAccessedKey = 'last_accessed', String accessCountKey = 'access_count', List<
String> readEvents = const ['read', 'get'], List<String> writeEvents = const ['write', 'put'], bool trackAccessCount = false, bool enableTouch = true, bool enableInit = true, int nowProvider()?}) - Creates an LRU plugin with configurable options.
Properties
- accessCountKey → String
-
Key in meta for access count.
final
- enableInit → bool
-
Whether to register init hook.
final
- enableTouch → bool
-
Whether to register touch hook.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastAccessedKey → String
-
Key in meta for last access timestamp.
final
- metaKey → String
-
Metadata key in ctx.data for entry metadata.
final
- nowProvider → int Function()?
-
Custom time provider for testing.
final
-
readEvents
→ List<
String> -
Events that trigger touch (update last_accessed).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- trackAccessCount → bool
-
Whether to track access count.
final
-
writeEvents
→ List<
String> -
Events that trigger init (set initial LRU metadata).
final
Methods
-
build(
) → HiPlugin - Builds the HiPlugin for installation.
-
frequentlyAccessedCondition(
{required int minAccessCount}) → HiCond - Creates a condition for "frequently accessed" with minimum count.
-
install(
HiEngine engine) → void - Convenience method to build and install in one step.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recentlyAccessedCondition(
{required int thresholdMs}) → HiCond - Creates a condition for "recently accessed" within threshold.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited