OpengraphCache class

In-memory cache for opengraph_fetch results.

Successfully fetched entities are cached by URL so repeated calls — for example widgets rebuilding inside scrollable lists — do not trigger a new network request. Failed fetches are NOT cached, so transient network errors recover on the next attempt.

Keys are normalized URLs: www.example.com and https://www.example.com address the same entry in get, put and evict.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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

Static Properties

clock DateTime Function()
Clock used to timestamp entries; replaceable in tests to simulate the passage of time without waiting.
getter/setter pair
enabled bool
Whether caching is enabled.
getter/setter pair
length int
Number of entries currently cached.
no setter
maxEntries int
Maximum number of cached entries. The oldest entries are evicted first.
getter/setter pair
ttl Duration?
How long a cached entry stays fresh. Stale entries are evicted on access, forcing a refetch. Set to null to keep entries for the whole session.
getter/setter pair

Static Methods

clear() → void
Clears all cached entries.
evict(String url) → void
Removes a single url from the cache.
get(String url, {Duration? maxAge}) OpenGraphEntity?
Returns the cached entity for url, or null when it is absent or older than maxAge (which defaults to ttl).
put(String url, OpenGraphEntity entity) → void
Stores an entity for url, evicting the oldest entries if needed.