Skip to content

Commit

Permalink
cache debug logging: Date.now() -> performance.now(); 6.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jan 8, 2024
1 parent 1918b63 commit be44b6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/caching.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const debug = require('debug')('match-gtfs-rt-to-gtfs:caching')
const {performance} = require('node:perf_hooks')
const pkg = require('../package.json')
const redis = require('./redis')

Expand All @@ -18,18 +19,18 @@ const withCaching = (fn, getId) => {
const cached = async (...args) => {
const id = getId(...args)

const t0 = Date.now()
const t0 = performance.now()
const fromCache = await redis.get(PREFIX + id)
debug(id, 'checking cache took', Date.now() - t0, 'from cache?', !!fromCache)
debug(id, 'checking cache took', Math.round(performance.now() - t0), 'from cache?', !!fromCache)
if (fromCache) {
const stale = JSON.parse(fromCache)
Object.defineProperty(stale || {}, CACHED, {value: true})
return stale
}

const t1 = Date.now()
const t1 = performance.now()
const fresh = await fn(...args)
debug(id, 'fetching fresh took', Date.now() - t1)
debug(id, 'fetching fresh took', Math.round(performance.now() - t1))

// todo: ignore errors
await redis.set(PREFIX + id, JSON.stringify(fresh), 'PX', TTL)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "match-gtfs-rt-to-gtfs",
"description": "Match GTFS Realtime data with GTFS Static data, even if they don't share an ID.",
"version": "6.4.2",
"version": "6.5.0",
"main": "index.js",
"bin": {
"build-gtfs-match-index": "build-index.js"
Expand Down

0 comments on commit be44b6b

Please sign in to comment.