* Determines if the cache should be refreshed based on the last checked time. * @param {number} duration - Duration in milliseconds for cache validity. * @returns {boolean} true if the cache should be refreshed, else false.
(duration = 1 * 60 * 60 * 1000)
| 42 | * @returns {boolean} true if the cache should be refreshed, else false. |
| 43 | */ |
| 44 | shouldRefresh(duration = 1 * 60 * 60 * 1000) { // Default: 1 hour |
| 45 | if (!this.lastChecked) { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | const now = Date.now(); |
| 50 | const elapsed = now - this.lastChecked; |
| 51 | const jitter = Math.floor(Math.random() * 15 * 60 * 1000); // Up to 15 minutes |
| 52 | return elapsed > (duration - jitter); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Clears the cache. |
no outgoing calls
no test coverage detected