import { JsonObject , ICache } from '../types' ; export class Cache implements ICache { /** Data that is stored in memory */ store : JsonObject ; /** Configuration on how long to keep in memory */ cacheExpiration : number ; /** Date when cache expires */ expires : number ; /** ETag of the object cached */ etag : string ; /** Document version id if versioning is enabled */ versionId : string ; param cacheExpiration constructor ( cacheExpiration ) { this . store = { } ; this . cacheExpiration = cacheExpiration ; this . expires = 0 ; this . etag = '' ; this . versionId = '' ; } param data set ( data , etag ? , versionId ? ) { this . store = data ; this . expires = new Date ( ) . getTime ( ) + this . cacheExpiration ; this . etag = etag ? etag : '' ; this . versionId = versionId ? versionId : '' ; } returns get ( ) { return this . store ; } returns getEtag ( ) { return this . etag ; } returns exists ( ) { if ( this . store && this . expires > new Date ( ) . getTime ( ) ) { return true ; } else { this . clear ( ) ; return false ; } } /**
     * Clears local cache
     */ clear ( ) { this . store = { } ; this . expires = 0 ; this . etag = '' ; } }