Best use of Jquery-ajax cache plugin

Source: Internet
Author: User
Tags sessionstorage

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.