export default ({ db }) => {
  const name = `cache${Math.random().toString(36)}`

  return {
    getManifest ({ user, repo, opts }, cb) {
      const key = createKey(`${name}~manifest`, { user, repo, opts })
      db.get(key, (err, manifest) => {
        if (err) return err.notFound ? cb() : cb(err)
        cb(null, manifest)
      })
    },

    setManifest ({ user, repo, opts }, manifest, cb) {
      const key = createKey(`${name}~manifest`, { user, repo, opts })
      db.put(key, manifest, cb)
    },

    getInfo ({ user, repo, opts }, cb) {
      const key = createKey(`${name}~info`, { user, repo, opts })
      db.get(key, (err, info) => {
        if (err) return err.notFound ? cb() : cb(err)
        cb(null, info)
      })
    },

    setInfo ({ user, repo, opts }, info, cb) {
      const key = createKey(`${name}~info`, { user, repo, opts })
      db.put(key, info, cb)
    }
  }
}

function createKey (prefix, { user, repo, opts }) {
  opts = opts || {}

  let key = `${prefix}~${user}~${repo}`

  if (opts.path && opts.path[opts.path.length - 1] === '/') {
    opts.path = opts.path.slice(0, -1)
  }

  if (opts.path) {
    key += `~${opts.path.replace(/\//g, '~')}`
  }

  return `${key}~#${opts.ref || ''}`
}

@@ -602,32 +602,68 @@
 , repo, opts %7D)%0A
+      console.log(%60getInfo $%7Bkey%7D%60)%0A
       db.get(key
@@ -880,32 +880,68 @@
 , repo, opts %7D)%0A
+      console.log(%60setInfo $%7Bkey%7D%60)%0A
       db.put(key

Add logs