-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: externalized cache eviction predicate
- Loading branch information
1 parent
95de9fc
commit f141b2e
Showing
4 changed files
with
42 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { StorageValue } from './types'; | ||
|
||
/** | ||
* Returns true if a storage value can still be used by checking his | ||
* createdAt and ttl values. | ||
* | ||
* @param value The stored value | ||
* @returns True if the cache can still be used | ||
*/ | ||
export function isCacheValid(value: StorageValue): boolean { | ||
if (!value) { | ||
return false; | ||
} | ||
|
||
if (value.state !== 'cached') { | ||
return false; | ||
} | ||
|
||
return value.createdAt + value.ttl > Date.now(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters