-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2277 from ptlthg/feat/configurable_cache_times
Add cache times to credentials.json
- Loading branch information
Showing
3 changed files
with
84 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import credentials from "./credentials.js"; | ||
|
||
/** | ||
* Check if a resource is expired based on the cache time | ||
* @param {number} unixMs Unix timestamp in milliseconds | ||
* @param {number} cacheTime The cache time in seconds | ||
* @returns {boolean} Whether the cache is expired | ||
*/ | ||
export function isCacheExpired(unixMs, cacheTime) { | ||
return Date.now() - unixMs > cacheTime * 1000; | ||
} | ||
|
||
/** | ||
* Check if a profile cache is expired based on the configured cache time | ||
* @param {number} unixMs Unix timestamp in milliseconds | ||
* @returns {boolean} Whether the cache is expired | ||
*/ | ||
export function isProfileCacheExpired(unixMs) { | ||
return isCacheExpired(unixMs, credentials.cacheSeconds.profiles); | ||
} | ||
|
||
/** | ||
* Check if a museum cache is expired based on the configured cache time | ||
* @param {number} unixMs Unix timestamp in milliseconds | ||
* @returns {boolean} Whether the cache is expired | ||
*/ | ||
export function isMuseumCacheExpired(unixMs) { | ||
return isCacheExpired(unixMs, credentials.cacheSeconds.museum); | ||
} | ||
|
||
/** | ||
* Check if a guild cache is expired based on the configured cache time | ||
* @param {number} unixMs Unix timestamp in milliseconds | ||
* @returns {boolean} Whether the cache is expired | ||
*/ | ||
export function isGuildCacheExpired(unixMs) { | ||
return isCacheExpired(unixMs, credentials.cacheSeconds.guild); | ||
} | ||
|
||
/** | ||
* Check if a bingo profile cache is expired based on the configured cache time | ||
* @param {number} unixMs Unix timestamp in milliseconds | ||
* @returns {boolean} Whether the cache is expired | ||
*/ | ||
export function isBingoProfileCacheExpired(unixMs) { | ||
return isCacheExpired(unixMs, credentials.cacheSeconds.bingoProfiles); | ||
} |
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