Skip to content

Commit 45c1603

Browse files
Debug cache
1 parent 82d5de9 commit 45c1603

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/acl-checker.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const rdf = require('rdflib')
55
const debug = require('./debug').ACL
6+
const debugCache = require('./debug').cache
67
const HTTPError = require('./http-error')
78
const aclCheck = require('@solid/acl-check')
89
const { URL } = require('url')
@@ -216,13 +217,20 @@ function fetchLocalOrRemote (mapper, serverUri) {
216217
return { body, contentType }
217218
}
218219
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)
221222
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),
223230
promise: doFetch(url)
224231
}
225232
}
233+
debugCache('Cache hit', url)
226234
const { body, contentType } = await temporaryCache[url].promise
227235
// Parse the file as Turtle
228236
rdf.parse(body, graph, url, contentType)

lib/debug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const debug = require('debug')
33
exports.handlers = debug('solid:handlers')
44
exports.errors = debug('solid:errors')
55
exports.ACL = debug('solid:ACL')
6+
exports.cache = debug('solid:cache')
67
exports.parse = debug('solid:parse')
78
exports.metadata = debug('solid:metadata')
89
exports.authentication = debug('solid:authentication')

0 commit comments

Comments
 (0)