var LocalStorage = /** @class */ (function () {
    function LocalStorage(prefix) {
        if (prefix === void 0) { prefix = ''; }
        this.prefix = '';
        this.cache = {};
        this.prefix = prefix ? prefix + '.' : '';
    }
    LocalStorage.prototype.setItem = function (key, value) {
        this.cache[key] = value;
        if (window.localStorage) {
            try {
                window.localStorage.setItem(this.prefix + key, JSON.stringify(value));
            }
            catch (error) {
                // Ignore
            }
        }
    };
    LocalStorage.prototype.getItem = function (key, defaultValue) {
        if (defaultValue === void 0) { defaultValue = undefined; }
        if (key in this.cache) {
            return this.cache[key];
        }
        if (window.localStorage) {
            try {
                var value = window.localStorage.getItem(this.prefix + key);
                if (value !== null) {
                    value = JSON.parse(value);
                    this.cache[key] = value;
                    return value;
                }
            }
            catch (error) {
                // Ignore
            }
            return defaultValue;
        }
    };
    return LocalStorage;
}());
export { LocalStorage };
//# sourceMappingURL=LocalStorage.js.map