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.

42 lines (41 loc) 1.49 kB
import { MemoryCacheClient } from '../cache-client'; /** * Base implementation of @see DictionaryService that handles caching dictionary values */ export 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 MemoryCacheClient(this.options); } }