jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

moment js object is not saved properly #261

Open MarcoAbi opened 7 years ago

MarcoAbi commented 7 years ago

by inserting a momentjs object, the cache will serialize it and, upon retrieval, only the string representation can be get.

Expected behaviour: the moment object is retrieved instead of its string representation.

Steps to reproduce:

var cacheOptions = {};
cacheOptions.storageMode = cacheOptions.storageMode || 'sessionStorage';
cacheOptions.deleteOnExpire = cacheOptions.deleteOnExpire || 'aggressive';
cacheOptions.recycleFreq = cacheOptions.recycleFreq || 60000;

console.log("creating cache: mm");
CacheFactory.createCache("mm", cacheOptions);
var cache = CacheFactory.get("mm");

var m = moment();
console.log(m);
cache.put("m", m);
var m1 = cache.get("m");
console.log(m1);

the code above will prints:

r {_isAMomentObject: true, _isUTC: false, _pf: Object, _locale: C, _d: Wed Jun 14 2017 00:21:53 GMT+0200 (CEST)…}

2017-06-13T22:21:53.672Z