ContextCache class

Multi-level LRU cache for app context.

Three cache levels with independent TTLs:

  • L1 (Global): user auth state, app config — TTL 5 minutes
  • L2 (Session): navigation stack, visited routes — TTL 30 seconds
  • L3 (Screen): current screen semantics snapshot — TTL configurable (default 10s)

Constructors

ContextCache({Duration screenTtl = const Duration(seconds: 10), ScreenContext onCaptureScreen()?, Future<Map<String, dynamic>> onCaptureGlobal()?})

Properties

hashCode int
The hash code for this object.
no setterinherited
onCaptureGlobal Future<Map<String, dynamic>> Function()?
Callback to capture fresh global context.
final
onCaptureScreen ScreenContext Function()?
Callback to capture fresh screen context.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
screenKnowledge Map<String, ScreenContext>
Get all cached screen knowledge for progressive learning.
no setter
screenTtl Duration
TTL for screen-level context (L3). Configurable.
final
wasDirty bool
no setter

Methods

clear() → void
Clear all caches.
getGlobalContext() Future<Map<String, dynamic>>
Get or rebuild the global context.
getScreenContext(String? currentRoute) ScreenContext
Get or rebuild the screen context for the current route.
getSessionContext() Map<String, dynamic>
Build the session context (nav stack + discovered routes).
invalidateAll() → void
Mark everything as stale (e.g., after login/logout).
invalidateScreen() → void
Mark the screen context as stale (e.g., after a route change or UI update).
invalidateSession() → void
Mark session context as stale (e.g., after app resume).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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