JSPM

html-cache

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q17887F
  • License MIT

Cache html content into RAM or Drive

Package Exports

  • html-cache

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

html-cache

Cache html content into RAM or Drive

Tieng Viet khong dau Tieng Viet khong dau

Install

$ npm install html-cache

Usage

Basic

var htmlCache = require('html-cache');

html.save('/home', '<!DOCTYPE html><html><body><h1>Home</h1></body></html>');

console.log(html.get('/home'));

Express

var express = require('express');
var htmlCache = require('html-cache');

var app = express();

app.set('views', './views');
app.set('view engine', 'pug');

app.get('/', (req, res) => {
    if (htmlCache.isCache(req.url)){
        res.send(htmlCache.get(req.url));
    } else {
        res.render('default/index', (err, html) => {
            htmlCache.save(req.url, html);
            return html;
        });
    }
});

app.listen(3000);

API

htmlCache.isCache( key ) [true/false]

htmlCache.save( key, value )

Save cache data

htmlCache.get( key ) [string]

Get cache data

htmlCache.remove( key ) [true/false]

Remove cache by key name

htmlCache.removeOldest()

Remove oldest cache

htmlCache.clear()

Remove all cache

htmlCache.total() [number]

Demo

See here

License

MIT