|
3 | 3 |
|
4 | 4 | const rdf = require('rdflib') |
5 | 5 | const debug = require('./debug').ACL |
| 6 | +const debugCache = require('./debug').cache |
6 | 7 | const HTTPError = require('./http-error') |
7 | 8 | const aclCheck = require('@solid/acl-check') |
8 | 9 | const { URL } = require('url') |
@@ -216,13 +217,20 @@ function fetchLocalOrRemote (mapper, serverUri) { |
216 | 217 | return { body, contentType } |
217 | 218 | } |
218 | 219 | return async function fetch (url, graph = rdf.graph()) { |
219 | | - if (!temporaryCache[url] || temporaryCache[url].timestamp < new Date().getTime() - EXPIRY_MS) { |
220 | | - debug(temporaryCache[url] ? `Repopulating cache, content is ${new Date().getTime() - temporaryCache[url].timestamp} ms old` : 'Populating cache', url) |
| 220 | + if (!temporaryCache[url]) { |
| 221 | + debugCache('Populating cache', url) |
221 | 222 | temporaryCache[url] = { |
222 | | - timestamp: new Date().getTime(), |
| 223 | + timer: setTimeout(() => { |
| 224 | + debugCache('Expunging from cache', url) |
| 225 | + delete temporaryCache[url] |
| 226 | + if (Object.keys(temporaryCache).length === 0) { |
| 227 | + debugCache('Cache is empty again') |
| 228 | + } |
| 229 | + }, EXPIRY_MS), |
223 | 230 | promise: doFetch(url) |
224 | 231 | } |
225 | 232 | } |
| 233 | + debugCache('Cache hit', url) |
226 | 234 | const { body, contentType } = await temporaryCache[url].promise |
227 | 235 | // Parse the file as Turtle |
228 | 236 | rdf.parse(body, graph, url, contentType) |
|
0 commit comments