0.1.5 • Published 5 years ago
gocache v0.1.5
gocache
Get-Or-CACHEd Caching structure, that returns a result of provided callback invocation with caching it for specified time. Expiration is not precise and may vary due to callback call duration.
Usage
let myCachedObject = new GOCache(5000, () => {
return Date.now();
})
setInterval(() => console.log(myCachedObject.get()), 1000)
// expected to print same number 5 times
with express.js, request-promise-native
let router = require('express').Router();
const GOCache = require("gocache");
const request = require('request-promise-native');
const TIME = 10000;
let CachedPage = new GOCache(TIME, async () => await request("https://google.com"))
Router.get('/cached-page', async (req, res) => res.send(CachedPage.get()));
FAQ
.get()
returns undefined or something else unwanted.Make sure your callback exactly returns data you want, not
pending promise
or something.