WeatherModule
Install
npm i @orzelius/weathermodule
Use like this (uncached):
const { weatherApp } = require('@orzelius/weathermodule');
//Uncached verson
weatherApp.getData('York', 1)
.then(data => console.log(data))
.catch(err => {
throw err;
});
First parameter is the name of the city and the second one is optional index, if more than one city is returned.
Or like this (cached):
const { weatherApp, DataCash } = require('@orzelius/weathermodule');
//Declare cache
const cachedWeatherApp = new DataCash(() => { return weatherApp.getData('York', 1) }, 0.05)
//Use cache
console.log(cachedWeatherApp.getData().then((data) => { console.log(!!data) }));
//Some timeouts to see it work
setTimeout(cachedWeatherApp.getData, 1000);
setTimeout(cachedWeatherApp.getData, 2000);
setTimeout(cachedWeatherApp.getData, 3000);
setTimeout(cachedWeatherApp.getData, 4000);
setTimeout(cachedWeatherApp.getData, 5000);
setTimeout(cachedWeatherApp.getData, 6000);
The 0.05 is cache ttl in minutes (3s in this case)