moment-cache
Moment-cache is a tiny tool to speed up your moment.js calls.
During the app lifecycle we can call moment oftentimes. Every call is time. Time is performance. This tool will increase performance of your app by caching moment.js instances.
Why?
; ; const dateString = '2016-08-24'; const momentCalls = 99999; const check = { let i = 0; const start = ; while i <= momentCalls ; i++; return - start; } console; // ~1588 ms console; // ~35 ms
Syntax:
Arguments:
-
date: See moment/parse.
-
format: See moment/format.
-
clone (by default - true): set false if you are not going to change instance in future. Will increase performance, but any object changes will affect cached result. See moment/clone.
; // or moment().cache const myDate = '06-28-2016'; const format = 'MM-DD-YYYY'; const date = ; // moment.js cached instance const anotherDate = ; // rapidly retrieving previously processed result from the cache
Methods:
updateStorage: change cache destination.
Arguments:
- storage: object where cache data is stored. By default - covert object behind the scenes.
; const myStorage = {}; cachable; const date = ; console; // {1471899600000: Moment}