UNPKG

site-validator-cli

Version:

A command line tool that takes a URL or a file, then uses html-validator (a wrapper for https://validator.w3.org/nu/) to validate each page.

46 lines (38 loc) 944 B
'use strict' const flatCache = require('flat-cache') module.exports = class Cache { constructor (name, path, cacheTime = 0) { this.name = name this.path = path this.cache = flatCache.load(name, path) this.expire = cacheTime === 0 ? false : cacheTime * 1000 * 60 } getKey (key) { var now = new Date().getTime() var value = this.cache.getKey(key) if (value === undefined) { return undefined } else if (value.expire !== false && value.expire < now) { this.removeKey(key) return undefined } else { return value.data } } setKey (key, value) { var now = new Date().getTime() this.cache.setKey(key, { expire: this.expire === false ? false : now + this.expire, data: value }) } removeKey (key) { this.cache.removeKey(key) } save () { this.cache.save(true) } remove () { flatCache.clearCacheById(this.name, this.path) } }