UserCache class
A cache for storing resolved users to prevent flickering in recycled widgets.
Uses a Least Recently Used (LRU) eviction strategy to limit memory usage. When the cache reaches the maximum size, the least recently accessed user will be removed to make space for new entries.
Extends ChangeNotifier to allow widgets to listen for cache modifications.
- Inheritance
-
- Object
- ChangeNotifier
- UserCache
Constructors
- UserCache.new({int maxSize = 100})
- Creates a user cache with the specified maximum size.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- maxSize → int
-
Maximum number of users to keep in the cache.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
clear(
) → void - Clears the entire cache.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
getOrResolve(
UserID userId, ResolveUserCallback resolveUser) → Future< User?> - Gets or resolves a user, updating the cache.
-
getSync(
UserID userId) → User? - Gets a user synchronously from cache, or returns null if not cached.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
remove(
UserID userId) → void - Removes a specific user from the cache.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateUser(
UserID userId, User? user) → void - Manually updates a user in the cache.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited