1 Star 2 Fork 0

tower1229-backup / AJAX-Cache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

中文 | English

AJAX-Cache

npm GitHub release license

:tophat:最好用的jQuery-Ajax缓存插件

介绍

AJAX-Cache是一款jQuery插件,基于localStorage/sessionStorage实现异步请求缓存功能,并提供“快照”和“定时”两种缓存模式。

安装

npm

npm i ajax-cache --save

Download

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

使用

你只需要为jQuery.ajax()增加一个localCache配置

开启快照缓存

$.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);
        }
    }
});

开启定时缓存

$.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);
    }
});

清除缓存

$.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);
    }
});

清除所有缓存

$.ajaxCache.clear();

配置

$.ajaxCache.set({
	storage: 'localStorage', 		//存储方式,默认"localStorage",可选择"sessionStorage"
	cacheNamePrefix: '_ajaxcache'	//存储前缀,通常不需要修改
});

演示

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

许可证

MIT

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

MIT License Copyright (c) 2018 refined-x Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

:tophat:The best jQuery-ajax-cache plugin 展开 收起
JavaScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/flxe/AJAX-Cache.git
git@gitee.com:flxe/AJAX-Cache.git
flxe
AJAX-Cache
AJAX-Cache
master

搜索帮助