Created
November 20, 2018 11:27
-
-
Save vella-nicholas/a424d1204fc82fbeee80c7eeb2bf7549 to your computer and use it in GitHub Desktop.
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
const maxAge = 30; // maximum cache age (min) | |
/** | |
* Gets the cached data for the specified request. | |
* @param url The request URL. | |
* @return The cached data or null if no cached data exists for this request. | |
*/ | |
getCacheData(url: string): HttpResponse<any> | null { | |
const cacheEntry = this.cachedData[url]; | |
if (cacheEntry) { | |
const exiprationDate = new Date(); | |
exiprationDate.setMinutes(exiprationDate.getMinutes() - maxAge); | |
if (new Date(exiprationDate).getTime() >= new Date(cacheEntry.lastUpdated).getTime()) { | |
return null; | |
} else { | |
return cacheEntry.data; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment