ng2-cache icon indicating copy to clipboard operation
ng2-cache copied to clipboard

Default cache options

Open sdeering opened this issue 7 years ago • 1 comments

HI, first off, great package its working well good job!

I noticed your using this for Default cache options.

/** * Default cache options */ private _defaultOptions: CacheOptionsInterface = { expires: Number.MAX_VALUE, maxAge : Number.MAX_VALUE };

How long is that exactly, am i reading it right to say its indefinite until the session cache is cleared?

If so, how would you set the cache to expire to say 1 day?

sdeering avatar Oct 10 '18 05:10 sdeering

Hi, thanks :)

    //put some data to cache "forever"
    //returns true is data was cached successfully, otherwise - false
    let result: boolean = this._cacheService.set('key', ['some data']);
    
    //put some data to cache for 5 minutes (maxAge - in seconds)
    this._cacheService.set('key', ['some data'], {maxAge: 5 * 60});

    //put some data to cache for 1 hour (expires - timestamp with milliseconds)
    this._cacheService.set('key', {'some': 'data'}, {expires: Date.now() + 1000 * 60 * 60});

    //put some data to cache with tag "tag"
    this._cacheService.set('key', 'some data', {tag: 'tag'});

just like in example PS "forever" means - until you didn't clear storage manually

Jackson88 avatar Feb 08 '19 17:02 Jackson88