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

moment js object is not saved properly

Open MarcoAbi opened this issue 8 years ago • 0 comments

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

MarcoAbi avatar Jun 13 '17 22:06 MarcoAbi