plugins/lru/lru library
LRU (Least Recently Used) plugin for hihook.
Provides conditions and hooks for LRU cache management.
Metadata Contract
Expects ctx.data['meta'] to contain:
last_accessed: int (milliseconds since epoch)access_count: int (optional, for access tracking)
Graceful Degradation
- No meta: allows operation (no enforcement)
- Missing LRU fields: allows operation (no enforcement)
Example Usage
final engine = HiEngine();
LruPlugin().install(engine);
// With custom configuration
LruPlugin(
trackAccessCount: true,
readEvents: ['read', 'get'],
).install(engine);
Classes
- LruPlugin
- LRU Plugin - Least Recently Used cache management.
Functions
-
lruFrequentlyAccessedCondition(
{String name = 'lru:frequentlyAccessed', String metaKey = 'meta', String accessCountKey = 'access_count', required int minAccessCount}) → HiCond - Creates an LRU condition based on access count threshold.
-
lruInitHook(
{String uid = 'lru:init', List< String> events = const ['write', 'put'], String metaKey = 'meta', String lastAccessedKey = 'last_accessed', String accessCountKey = 'access_count', int nowProvider()?, HiPhase phase = HiPhase.post, int priority = 0}) → HiHook - Creates an LRU initialization hook for new entries.
-
lruRecentlyAccessedCondition(
{String name = 'lru:recentlyAccessed', String metaKey = 'meta', String lastAccessedKey = 'last_accessed', required int thresholdMs, int nowProvider()?}) → HiCond - Creates an LRU condition that checks if an entry was accessed recently.
-
lruTouchHook(
{String uid = 'lru:touch', List< String> events = const ['read', 'get'], String metaKey = 'meta', String lastAccessedKey = 'last_accessed', String accessCountKey = 'access_count', bool trackAccessCount = false, int nowProvider()?, HiPhase phase = HiPhase.post, int priority = 0}) → HiHook - Creates an LRU touch hook that updates access metadata on read.