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

logRequests

parent b651d998
// this is aliased in webpack config based on server/client build
import { createAPI } from 'create-api'
const logRequests = !!process.env.DEBUG_API
const api = createAPI({
version: '/v0',
config: {
......@@ -20,8 +22,10 @@ function warmCache () {
}
function fetch (child) {
logRequests && console.log(`fetching ${child}...`)
const cache = api.cachedItems
if (cache && cache.has(child)) {
logRequests && console.log(`cache hit for ${child}.`)
return Promise.resolve(cache.get(child))
} else {
return new Promise((resolve, reject) => {
......@@ -30,6 +34,7 @@ function fetch (child) {
// mark the timestamp when this item is cached
if (val) val.__lastUpdated = Date.now()
cache && cache.set(child, val)
logRequests && console.log(`fetched ${child}.`)
resolve(val)
}, 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