Skip to content

Commit

Permalink
Prevent stale data from getting returned from the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Greenheart committed Jun 17, 2024
1 parent 56c1dae commit e2f9af1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/createCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createCache<K, V>({ maxAge }: { maxAge: number }) {
},
get(key: K) {
const value = cache.get(key)
if (value) {
if (value && Date.now() - value.cachedAt < maxAge) {
return value.data
}
},
Expand Down

0 comments on commit e2f9af1

Please sign in to comment.