@ima/core
Version:
IMA.js framework for isomorphic javascript application
92 lines • 2.59 kB
TypeScript
import * as Helpers from '@ima/helpers';
import { Cache } from './Cache';
import { CacheEntry, SerializedCacheEntry } from './CacheEntry';
import { CacheFactory } from './CacheFactory';
import { Storage } from '../storage/Storage';
/**
* Configurable generic implementation of the {@link Cache} interface.
*
* @example
* if (cache.has('model.articles')) {
* return cache.get('model.articles');
* } else {
* let articles = getArticlesFromStorage();
* // cache for an hour
* cache.set('model.articles', articles, 60 * 60 * 1000);
* }
*/
export declare class CacheImpl<V> extends Cache<V> {
protected _cache: Storage<CacheEntry<V>>;
protected _factory: CacheFactory<V>;
protected _Helper: typeof Helpers;
protected _ttl: number;
protected _enabled: boolean;
/**
* Initializes the cache.
*
* @param cacheStorage The cache entry storage to use.
* @param factory Which create new instance of cache entry.
* @param Helper The IMA.js helper methods.
* @param config The cache configuration.
*/
constructor(cacheStorage: Storage<CacheEntry<V>>, factory: CacheFactory<V>, Helper: typeof Helpers, { ttl, enabled }: {
ttl?: number | undefined;
enabled?: boolean | undefined;
});
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
has(key: string): boolean;
/**
* @inheritDoc
*/
get(key: string): V | null;
/**
* @inheritDoc
*/
set(key: string, value: V, ttl?: number | string): void;
/**
* @inheritDoc
*/
delete(key: string): void;
/**
* @inheritDoc
*/
disable(): void;
/**
* @inheritDoc
*/
enable(): void;
/**
* @inheritDoc
*/
serialize(): string;
/**
* @inheritDoc
*/
deserialize(serializedData: {
[key: string]: SerializedCacheEntry<V>;
}): void;
/**
* Tests whether the provided value can be serialized into JSON.
*
* @param value The value to test whether or not it can be serialized.
* @return `true` if the provided value can be serialized into JSON,
* `false` otherwise.
*/
private _canSerializeValue;
/**
* Attempts to clone the provided value, if possible. Values that cannot be
* cloned (e.g. promises) will be simply returned.
*
* @param value The value to clone.
* @return The created clone, or the provided value if the value cannot be
* cloned.
*/
private _clone;
}
//# sourceMappingURL=CacheImpl.d.ts.map