all files / commons/utils/ cacheUtil.js

100% Statements 18/18
100% Branches 7/7
100% Functions 5/5
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                                                   
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Class which holds helper tools when working with cache.
 *
 * @export
 * @class CacheUtil
 */
var CacheUtil = (function () {
    function CacheUtil() {
        this.cache = {};
    }
    /**
     * Add new key/value pair in cache
     * @param {string} primeKey - primary identicator
     * @param {string} key - unique string value
     * @param {Everything} value - value object to be added in cache
     */
    CacheUtil.prototype.add = function (primeKey, key, value) {
        if (!this.cache[primeKey]) {
            this.cache[primeKey] = (_a = {}, _a[key] = value, _a);
        }
        else {
            this.cache[primeKey][key] = value;
        }
        var _a;
    };
    /**
     * Get data by key from cache
     * @param {string} primeKey - primary identicator
     * @param {string} key - key saved in cache
     * @return {*} value out of cache
     */
    CacheUtil.prototype.get = function (primeKey, key) {
        if ((primeKey && key) && this.cache[primeKey]) {
            return this.cache[primeKey][key];
        }
        return false;
    };
    /**
     * Get cache information by prime key
     * @param {string} primeKey key where to get the cache from
     * @return {*} get cache at prime key
     */
    CacheUtil.prototype.getByPrimeKey = function (primeKey) {
        return this.cache[primeKey];
    };
    return CacheUtil;
}());
exports.CacheUtil = CacheUtil;
exports.default = new CacheUtil();