INNER CODE UNIT · JavaScript
generateKey
leemonade/leemons · packages/leemons-cache/src/types/node/index.js:6
function generateKey(key, pluginName) {
return `${pluginName}.${key}`;
}
function cleanKey(key, pluginName) {
return key.replace(new RegExp(`^${pluginName}\\.`), '');
}
module.exports = function nodeCache() {
const cache = new NodeCache();
return (pluginName) => ({
get: async (key) => cache.get(generateKey(key, pluginName)),
has: async (key) => cache.has(generateKey(key, pluginName)),
set: async (key, value, ttl) => cache.set(generateKey(key, pluginName), value, ttl),
delete: async (key) => {
if (Array.isArray(key)) {
throw new Error('Delete only supports single key deletions');
}