Commit 49645e49 authored by Evan You's avatar Evan You

logRequests

parent b651d998
// this is aliased in webpack config based on server/client build // this is aliased in webpack config based on server/client build
import { createAPI } from 'create-api' import { createAPI } from 'create-api'
const logRequests = !!process.env.DEBUG_API
const api = createAPI({ const api = createAPI({
version: '/v0', version: '/v0',
config: { config: {
...@@ -20,8 +22,10 @@ function warmCache () { ...@@ -20,8 +22,10 @@ function warmCache () {
} }
function fetch (child) { function fetch (child) {
logRequests && console.log(`fetching ${child}...`)
const cache = api.cachedItems const cache = api.cachedItems
if (cache && cache.has(child)) { if (cache && cache.has(child)) {
logRequests && console.log(`cache hit for ${child}.`)
return Promise.resolve(cache.get(child)) return Promise.resolve(cache.get(child))
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -30,6 +34,7 @@ function fetch (child) { ...@@ -30,6 +34,7 @@ function fetch (child) {
// mark the timestamp when this item is cached // mark the timestamp when this item is cached
if (val) val.__lastUpdated = Date.now() if (val) val.__lastUpdated = Date.now()
cache && cache.set(child, val) cache && cache.set(child, val)
logRequests && console.log(`fetched ${child}.`)
resolve(val) resolve(val)
}, reject) }, reject)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment