vcache.js
function vcache_load(msg, reply) {
    var self = this
    var load_prior = this.prior
    var qent = msg.qent

    // Verify id format is compatible

    if (!msg.q.id || Object.keys(msg.q).length !== 1) {
      return load_prior.call(self, msg, reply)
    }

    var id = msg.q.id

    // Lookup version key

    var vkey = versionKey(qent, id)
    this.act({ role: 'cache', cmd: 'get' }, { key: vkey }, function(
      err,
      result
    ) {
      var version = result && result.value

      if (err) {
        ++stats.cache_errs
        return reply(err)
      }

      ++stats.get

      // Version not found

      if (null == version || version === -1) {
        // Item dropped from cache

        ++stats.vmiss
        self.log.debug('miss', 'version', vkey)
        self.log.debug('miss', qent, id, 0)

        // Pass to lower priority handler

        return load_prior.call(self, msg, function(err, ent) {
          if (err || !ent) {
            // Error or not found
            return reply(err)
          }

          writeKey(self, vkey, function(err) {
            if (err) {
              return reply(err)
            }

            return writeData(self, ent, 0, function(err, version) {
              return reply(err || ent)
            })
          })
        })
      }

      // Version found

      ++stats.vhit
      var key = dataKey(qent, id, version)
      var record = cache.get(key)
      if (record) {
        // Entry found (cache)

        self.log.debug('hit', 'lru', key)
        ++stats.lru_hit
        return reply(qent.make$(record))
      }

      // Entry not found (evicted from cache)

      self.log.debug('miss', 'lru', key)
      ++stats.lru_miss

      self.act({ role: 'cache', cmd: 'get' }, { key: key }, function(
        err,
        result
      ) {
        var ent = result && result.value

        if (err) {
          ++stats.cache_errs
          return reply(err)
        }

        // Entry found (upstream)

        if (ent) {
          ++stats.net_hit
          cache.set(key, ent)
          self.log.debug('hit', 'net', key)
          return reply(qent.make$(ent))
        }

        // Not found (upstream)

        ++stats.net_miss
        self.log.debug('miss', 'net', key)
        return reply()
      })
    })
  }
function vcache_load(msg, reply) {
    var self = this
    var load_prior = this.prior
    var qent = msg.qent

    // Verify id format is compatible

    if (!msg.q.id || Object.keys(msg.q).length !== 1) {
      return load_prior.call(self, msg, reply)
    }

    var id = msg.q.id

    // Lookup version key

    var vkey = versionKey(qent, id)
    this.act({ role: 'cache', cmd: 'get' }, { key: vkey }, function(
      err,
      result
    ) {
      var version = result && result.value

      if (err) {
        ++stats.cache_errs
        return reply(err)
      }

      ++stats.get

      // Version not found

      if (null == version || version === -1) {
        // Item dropped from cache

        ++stats.vmiss
        self.log.debug('miss', 'version', vkey)
        self.log.debug('miss', qent, id, 0)

        // Pass to lower priority handler

        return load_prior.call(self, msg, function(err, ent) {
          if (err || !ent) {
            // Error or not found
            return reply(err)
          }

          writeKey(self, vkey, function(err) {
            if (err) {
              return reply(err)
            }

            return writeData(self, ent, 0, function(err, version) {
              return reply(err || ent)
            })
          })
        })
      }

      // Version found

      ++stats.vhit
      var key = dataKey(qent, id, version)
      var record = cache.get(key)
      if (record) {
        // Entry found (cache)

        self.log.debug('hit', 'lru', key)
        ++stats.lru_hit
        return reply(qent.make$(record))
      }

      // Entry not found (evicted from cache)

      self.log.debug('miss', 'lru', key)
      ++stats.lru_miss

      self.act({ role: 'cache', cmd: 'get' }, { key: key }, function(
        err,
        result
      ) {
        var ent = result && result.value

        if (err) {
          ++stats.cache_errs
          return reply(err)
        }

        // Entry found (upstream)

        if (ent) {
          ++stats.net_hit
          cache.set(key, ent)
          self.log.debug('hit', 'net', key)
          return reply(qent.make$(ent))
        }

        // Not found (upstream)

        ++stats.net_miss
        self.log.debug('miss', 'net', key)
        return reply()
      })
    })
  }
Cache read