<commit_before>const cacheManager = require('cache-manager')
const oneMonth = 30 * 24 * 3600 * 1000
const store = require('./store')

module.exports = {
  init: function (server) {
    const ttl = server.options.ttl || 2 * oneMonth
    this.options = { ttl }
    console.log('using prerender-level-cache', this.options)
    this.cache = cacheManager.caching({ store })
  },

  requestReceived: function (req, res, next) {
    if (req.method !== 'GET') return next()
    if (req.refresh === true) return next()
    const { url } = req.prerender

    this.cache.get(url, function (err, result) {
      if (err) console.error(err)

      if (!err && result) {
        console.log('cache hit')
        req.prerender.cacheHit = true;
        return res.send(200, result)
      } else {
        next()
      }
    })
  },

  beforeSend: function (req, res, next) {
    const { url, content } = req.prerender
    this.cache.set(url, content, this.options, (err, result) => {
      if (err) console.error(err)
      else next()
    })
  }
}
<commit_msg>levelCache: make cache miss log less frightening<commit_after>const cacheManager = require('cache-manager')
const oneMonth = 30 * 24 * 3600 * 1000
const store = require('./store')

module.exports = {
  init: function (server) {
    const ttl = server.options.ttl || 2 * oneMonth
    this.options = { ttl }
    console.log('using prerender-level-cache', this.options)
    this.cache = cacheManager.caching({ store })
  },

  requestReceived: function (req, res, next) {
    if (req.method !== 'GET') return next()
    if (req.refresh === true) return next()
    const { url } = req.prerender

    this.cache.get(url, function (err, result) {
      if (err) {
        if (err.name === 'NotFoundError') console.log('cache miss', url)
        else console.error(err)
        next()
      } else if (result) {
        console.log('cache hit', url)
        req.prerender.cacheHit = true;
        res.send(200, result)
      } else {
        next()
      }
    })
  },

  beforeSend: function (req, res, next) {
    const { url, content } = req.prerender
    this.cache.set(url, content, this.options, (err, result) => {
      if (err) console.error(err)
      else next()
    })
  }
}

{'fraction_non_alphanumeric': 0.1506294964028777, 'fraction_numerical': 0.014388489208633094, 'mean_word_length': 2.600323624595469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5128694', 'n_tokens_mistral': 749, 'n_tokens_neox': 704, 'n_words': 184}