Commit 9ac29370 by Chavee Issariyapat

add cache module to store shadow and status data

parent b1d2b106
module.exports = { getStatus, getShadow, setStatus, setShadow, clear, clearAll }
const LRU = require("lru-cache");
let cache = new LRU({
max: 500
});
function getStatus(deviceid) {
return cache.get(`${deviceid}:status`);
}
function getShadow(deviceid) {
return cache.get(`${deviceid}:shadow`);
}
function setStatus(deviceid, data) {
return cache.set(`${deviceid}:status`, data);
}
function setShadow(deviceid, data) {
return cache.set(`${deviceid}:shadow`, data);
}
function clear(deviceid) {
cache.del(`${deviceid}:status`);
cache.del(`${deviceid}:shadow`);
}
function clearAll() {
cache.reset();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment