Ajax-cache
Best use of Jquery-ajax cache plugin
Introduced
Ajax-cache is a jquery plug-in that implements asynchronous request caching based on Localstorage/sessionstorage and provides both "snapshot" and "timed" cache modes.
Installing NPM
NPM I ajax-cache--save
Download
Https://github.com/tower1229/AJAX-Cache
Use
You only need to add a configuration for Jquery.ajax () localCache
Turn on snapshot caching
$.ajax ({ "http://rapapi.org/mockjsdata/9195/common/getRandom", dataType:' json ', ' snapshot ', function(res) { if (res.snapshot) { Console.log (' [snapshot] ' + res.data); Else { console.log (' [Remote Data] ' + Res.data);}}} );
Turn on timed cache
$.ajax ({ "http://rapapi.org/mockjsdata/9195/common/getRandom", dataType:' json ', thefunction(res) { console.log (' \n[cachingfor 5 seconds] ' + res.data); });
Clear Cache
$.ajax ({ "http://rapapi.org/mockjsdata/9195/common/getRandom", dataType:' json ', false , function (res) { console.log (' Cache has been cleared '); Console.log (Res.data); }});
Clear all Caches
$.ajaxcache.clear ();
Configuration
$.ajaxcache.set ({ ' localstorage ', // storage mode, default "Localstorage", selectable "sessionstorage" cachenameprefix: ' _ajaxcache ' // store prefix, usually without modification });
Demonstrate
http://refined-x.com/AJAX-Cache/test/
License
MIT
Copyright (c) 2017-present, refined-x.com
Best use of Jquery-ajax cache plugin