RateLimitResource class final

A thread-safe in-memory resource for storing rate limit entries.

This implementation uses a HashMap<Object, RateLimitEntry> as the underlying storage mechanism. Each key represents a unique identifier (e.g., user ID, API key), and each value is a RateLimitEntry that tracks usage counts, timestamps, and reset information.

This class implements Resource, making it compatible with JetLeaf's resource and pod management system.

Behavior

  • Stores and retrieves RateLimitEntry instances in memory.
  • Keys are arbitrary objects but typically strings or integers.
  • Designed for fast, concurrent access within a single application instance.
  • Not distributed; for clustered environments, a distributed rate limit storage should be used instead.

Example

final storage = ConcurrentMapRateLimitResource();
storage['user:123'] = RateLimitEntryImpl();
final entry = storage['user:123'];
  • RateLimitEntry: Represents individual rate limit data for a key.
  • Resource: Base interface for JetLeaf resources.
Implemented types

Constructors

RateLimitResource()
A thread-safe in-memory resource for storing rate limit entries.

Properties

entries Iterable<MapEntry<Object, RateLimitEntry>>
The map entries of this Map.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether there is no key/value pair in the map.
no setterinherited
isNotEmpty bool
Whether there is at least one key/value pair in the map.
no setterinherited
keys Iterable<Object>
The keys of this Map.
no setterinherited
length int
The number of key/value pairs in the map.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
values Iterable<RateLimitEntry>
The values of this Map.
no setterinherited

Methods

addAll(Map<Object, RateLimitEntry> other) → void
Adds all key/value pairs of other to this map.
inherited
addEntries(Iterable<MapEntry<Object, RateLimitEntry>> newEntries) → void
Adds all key/value pairs of newEntries to this map.
inherited
cast<RK, RV>() Map<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary.
inherited
clear() → void
Removes all entries from the map.
inherited
containsKey(Object? key) bool
Whether this map contains the given key.
inherited
containsValue(Object? value) bool
Whether this map contains the given value.
inherited
exists(Object key) bool
Determines whether an entry associated with the given key exists.
forEach(void action(Object key, RateLimitEntry value)) → void
Applies action to each key/value pair of the map.
inherited
get(Object key) RateLimitEntry?
Retrieves the value associated with the given key, if any.
map<K2, V2>(MapEntry<K2, V2> convert(Object key, RateLimitEntry value)) Map<K2, V2>
Returns a new map where all entries of this map are transformed by the given convert function.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
putIfAbsent(Object key, RateLimitEntry ifAbsent()) RateLimitEntry
Look up the value of key, or add a new entry if it isn't there.
inherited
remove(Object? key) RateLimitEntry?
Removes key and its associated value, if present, from the map.
inherited
removeWhere(bool test(Object key, RateLimitEntry value)) → void
Removes all entries of this map that satisfy the given test.
inherited
toString() String
A string representation of this object.
inherited
update(Object key, RateLimitEntry update(RateLimitEntry value), {RateLimitEntry ifAbsent()?}) RateLimitEntry
Updates the value for the provided key.
inherited
updateAll(RateLimitEntry update(Object key, RateLimitEntry value)) → void
Updates all values.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](Object? key) RateLimitEntry?
The value for the given key, or null if key is not in the map.
inherited
operator []=(Object key, RateLimitEntry value) → void
Associates the key with the given value.
inherited