Coder Social home page Coder Social logo

17605094230 / ajax-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tower1229/ajax-cache

0.0 0.0 0.0 15 KB

:tophat:The best jQuery-ajax-cache plugin

Home Page: http://refined-x.com/AJAX-Cache/

License: MIT License

JavaScript 65.01% HTML 34.99%

ajax-cache's Introduction

English | 中文

AJAX-Cache

npm GitHub release license

🎩The best jQuery-ajax-cache plugin

Introduction

AJAX-Cache is a jQuery plug-in. It implements asynchronous request caching based on localStorage/sessionStorage, and provides two cache modes: snapshot and timer.

Install

npm

npm i ajax-cache --save

Download

https://github.com/tower1229/AJAX-Cache

Usage

You only need to add a localCache configuration for jQuery.ajax ()

Open the snapshot cache

$.ajax({
    url: "http://rapapi.org/mockjsdata/9195/common/getRandom",
    dataType:'json',
    localCache: 'snapshot',
    success: function(res) {
        if (res.snapshot) {
            console.log('[snapshot] ' + res.data);
        } else {
            console.log('[remote data] ' + res.data);
        }
    }
});

Open the timing caching

$.ajax({
    url: "http://rapapi.org/mockjsdata/9195/common/getRandom",
    dataType:'json',
    localCache: 5000,
    success: function(res) {
        console.log('\n[Caching for 5 seconds] ' + res.data);
    }
});

Scavenging caching

$.ajax({
    url: "http://rapapi.org/mockjsdata/9195/common/getRandom",
    dataType:'json',
    localCache: false,
    success: function(res) {
    	console.log('Cache has been cleared');
        console.log(res.data);
    }
});

Scavenging all caches

$.ajaxCache.clear();

Configuration

$.ajaxCache.set({
	storage: 'localStorage', 		//Storage mode, default "localStorage", optional "sessionStorage"
	cacheNamePrefix: '_ajaxcache'	//Storage prefix, usually without modification
});

Live Example

http://refined-x.com/AJAX-Cache/test/

License

MIT

Copyright (c) 2017-present, refined-x.com

ajax-cache's People

Contributors

tower1229 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.