/************************************************************************* * Copyright 2022 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ /** * @ignore */ export declare enum CacheScope { /** * Default - Same as USER */ DEFAULT = "user", /** * Cache data at the IMS Org level. */ ORG = "org", /** * Cache data at the AEP Sandbox level. */ SANDBOX = "sandbox", /** * Cache data at the Sub Org level. */ SUBORG = "suborg", /** * Cache data at the user level. */ USER = "user" } /** * @ignore */ export declare enum CacheTTL { /** * Disable caching for this value. */ DONT_CACHE = 0, /** * Cache data for the duration of the current IMS session only * Data will not be available once the user has logged in again. */ IMS_SESSION = -1, /** * Default - One week */ DEFAULT = 604800, /** * Cache data for an hour. */ HOUR = 3600, /** * Cache data for a day. */ DAY = 86400, /** * Cache data for a week. */ WEEK = 604800, /** * Cache data for a month (30 days actual). */ MONTH = 2592000 } export type CacheExpiry = CacheTTL | number; /** * Input parameters for the Cache get and delete APIs. */ export interface CacheParameters extends CacheStoreParameters { /** * Cache key. */ key: string; /** * Cache scope (Optional - Defaults to user). */ scope?: CacheScope; } /** * Input parameters for bare bones Cache API */ export interface CacheStoreParameters { /** * Shared Cache name. * Calling app must be allowlisted by Unified Shell to access this cache. */ sharedCache?: string; } /** * Input parameters for the Cache set API. */ export interface CacheSetParameters extends CacheParameters { /** * Cache expiry. Can be one of the set values defined by CacheTTL, or a numeric cache ttl (in seconds). * Optional - Defaults to one week. */ expiry?: CacheExpiry; /** * Data to cache. Data must be serializable (JSON). */ value: T; } export declare enum CacheMethod { DELETE = "DELETE", GET = "GET", LIST_KEYS = "LIST_KEYS", POST = "POST" } /** * Cache entry (Returned by the get API). */ export type CacheEntry = { createdAt: number; key: string; value: T; } & ({ expiresAt: number; } | { expireBySession: true; }); /** * APIs for managing a client side persisted cache. */ export interface CacheApi { /** * Deletes a value from the cache (If available). * @param params Parameters used to identify the cached item to delete. */ delete(params: CacheParameters): Promise; /** * Gets a value from the cache if one is available. * @param params Parameters used to identify the cached item to retrieve. * @returns A promise that resolves to the specified value, or undefined if none exist. */ get(params: CacheParameters): Promise | undefined>; /** * Returns an array of strings representing the keys of the Cache. */ keys(params?: CacheStoreParameters): Promise; /** * Stores a value in the cache. * @param params Parameters used to identify the cached item to store and control its TTL. */ set(params: CacheSetParameters): Promise; } declare const cache: CacheApi; export default cache;