UNPKG

@sitecore-jss/sitecore-jss

Version:

This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains the core JSS APIs (layout service) and utilities.

46 lines (45 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DictionaryServiceBase = void 0; const cache_client_1 = require("../cache-client"); /** * Base implementation of @see DictionaryService that handles caching dictionary values */ class DictionaryServiceBase { /** * Initializes a new instance of @see DictionaryService using the provided @see CacheOptions * @param {CacheOptions} options Configuration options */ constructor(options) { this.options = options; this.cache = this.getCacheClient(); } /** * Caches a @see DictionaryPhrases value for the specified cache key. * @param {string} key The cache key. * @param {DictionaryPhrases} value The value to cache. * @returns The value added to the cache. * @mixes CacheClient<DictionaryPhrases> */ setCacheValue(key, value) { return this.cache.setCacheValue(key, value); } /** * Retrieves a @see DictionaryPhrases value from the cache. * @param {string} key The cache key. * @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache. */ getCacheValue(key) { return this.cache.getCacheValue(key); } /** * Gets a cache client that can cache data. Uses memory-cache as the default * library for caching (@see MemoryCacheClient). Override this method if you * want to use something else. * @returns {CacheClient} implementation */ getCacheClient() { return new cache_client_1.MemoryCacheClient(this.options); } } exports.DictionaryServiceBase = DictionaryServiceBase;