diff --git a/resources/Table.ts b/resources/Table.ts index 628289133..7cea816bf 100644 --- a/resources/Table.ts +++ b/resources/Table.ts @@ -2436,17 +2436,17 @@ export function makeTable(options) { if (entry?.then) return entry.then(transform.bind(this)); record = entry?.value; } - if ( - (checkLoaded && entry?.metadataFlags & (INVALIDATED | EVICTED)) || // invalidated or evicted should go to load from source - (entry?.expiresAt != undefined && entry?.expiresAt < Date.now()) - ) { - // should expiration really apply? - if (context.onlyIfCached) { - return { - [primaryKey]: entry.key, - message: 'This entry has expired', - }; - } + const isExpired = entry?.expiresAt != undefined && entry?.expiresAt < Date.now(); + const needsRefresh = checkLoaded && Boolean(entry?.metadataFlags & (INVALIDATED | EVICTED)); + if ((isExpired || needsRefresh) && context.onlyIfCached) { + return { + [primaryKey]: entry.key, + message: 'This entry has expired/invalidated', + }; + } + if (needsRefresh) { + // invalidated or evicted should go to load from source; TTL-expired entries are + // returned as stale data during search — freshness is enforced by get(), not search() const loadingFromSource = ensureLoadedFromSource(source, entry.key ?? entry, entry, context); if (loadingFromSource?.then) { return loadingFromSource.then(transform);