lib/cache.js
function check_object(now, key, p, c_info) {
        // keep track of how many files we're in the process of checking via
        // callback so we can know when to emit the 'ready' event
        stale_check_cnt++;

        if (!c_info.last_stat || (now - c_info.last_stat) > self.ttl_ms) {
            // consider it stale, cleanup locally cached file, if it exists
            fs.unlink(c_info._cacheFile, function (u_err) {
                // ignore errors deleting the cachefile, which may not exist
                log.trace('stale, discard: %s', p);
                stale_check_cnt--;
                if (db_keys_done && stale_check_cnt === 0)
                    self.emit('ready');
            });
        } else {
            // Our metadata is fresh, see if we have the object cached so we
            // can track its size.
            fs.stat(c_info._cacheFile, function (err, stats) {
                if (!err) {
                    // The file is still fresh, add to the current cache space
                    // used.
                    log.trace('not stale, keep: %s', p);
                    self._grow_cache(p, stats.size);
                }

                stale_check_cnt--;
                if (db_keys_done && stale_check_cnt === 0)
                    self.emit('ready');
            });
        }
    }
function check_object(now, key, p, c_info) {
        // keep track of how many files we're in the process of checking via
        // callback so we can know when to emit the 'ready' event
        stale_check_cnt++;

        if (!c_info.last_stat || (now - c_info.last_stat) > self.ttl_ms) {
            // consider it stale, cleanup locally cached file, if it exists
            fs.unlink(c_info._cacheFile, function (u_err) {
                // ignore errors deleting the cachefile, which may not exist
                log.trace('stale, discard: %s', p);
                stale_check_cnt--;
                if (db_keys_done && stale_check_cnt === 0)
                    self.emit('ready');
            });
        } else {
            // Our metadata is fresh, see if we have the object cached so we
            // can track its size.
            fs.stat(c_info._cacheFile, function (err, stats) {
                if (!err) {
                    // The file is still fresh, add to the current cache space
                    // used.
                    log.trace('not stale, keep: %s', p);
                    self._grow_cache(p, stats.size);
                }

                stale_check_cnt--;
                if (db_keys_done && stale_check_cnt === 0)
                    self.emit('ready');
            });
        }
    }
When we come up, we need to check each of the cached objects to see if the object is stale. If we have the local file cached then we keep our local copy as long as the local file is not expired, otherwise we just discard it. We don't try to check manta for each object since that would make the server startup time unacceptably long when we have a lot of cached objects.  We assume that this function is never called for dirty objects.