menu

SFRA / Server-side JS / Source: modules/server/simpleCache.js

'use strict';

/**
 * Represents a simple key/value store
 * @param {Object} [store] - a bracket notation-compatible object
 */
function SimpleCache(store) {
    this.store = store || {};
}

/**
 * Gets a value in key/value store
 * @param {string} key - the Key
 * @returns {Object} the stored value
 */
SimpleCache.prototype.get = function (key) {
    return this.store[key];
};

/**
 * Sets a value in key/value store
 * @param {string} key - the Key
 * @param {Object} [value] - the Value to store
 */
SimpleCache.prototype.set = function (key, value) {
    this.store[key] = value;
};

/**
 * Clears values from KV store
 */
SimpleCache.prototype.clear = function () {
    var store = this.store;
    Object.keys(store).forEach(function (key) {
        store[key] = null;
    });
};

module.exports = SimpleCache;

X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.