jquery cache ajax,AJAX-Cache | :tophat:The best jQuery-ajax-cache plugin

English

AJAX-Cache

ajax-cache.svgAJAX-Cache.svgAJAX-Cache.svg

:tophat: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 if (res.snapshootEqual) {

console.log('remote data is equal snapshot');

} 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

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

This site is open source. Improve this page.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值