ASIHTTPRequest缓存策略的设置

ASIHTTPRequest 是一款强大的网络请求框架,该框架自带了数据的缓存策略,下面来介绍该功能的使用方法。

 

1.创建缓存对象

            //创建缓存对象
            ASIDownloadCache *asiCache = [[ASIDownloadCache alloc] init];
            //设置缓存目录,这里设置沙盒目录下的Documents目录作为缓存目录
            NSString *document = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
            [asiCache setStoragePath:document];
            //设置缓存策略
            [asiCache setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
 

2.请求对象设置缓存

    //创建数据请求对象
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlstring]];
    /*
     *设置缓存策略
     *ASICacheForSessionDurationCacheStoragePolicy 程序下次启动会清除本地的缓存数据
     *ASICachePermanentlyCacheStoragePolicy 是持久缓存,程序下次启动,缓存仍然还在
     */
    request.cacheStoragePolicy = ASICachePermanentlyCacheStoragePolicy;
    [request setDownloadCache:[UserContext shareInstance].cache];
    //开始异步请求网络
    [request startAsynchronous];
 

 

3.数据请求完成后

    //网络数据加载完成后调用的block
    [request setCompletionBlock:^{
        NSString *responseString = request.responseString;
        //打印返回的数据
        NSLog(@"%@",responseString);
        
       //判断返回的数据是否来自本地缓存
        if (request.didUseCachedResponse) {
            NSLog(@"使用缓存数据");
        } else {
            NSLog(@"请求网络数据");
        }
        
    }];
 

 

【2024遥感应用组一等奖】基于时空融合和水量平衡法的若尔盖高原水源涵养功能评价 考虑到水源涵养的概念和尺度特征、数据的可获得性、模型的模拟精度等,构建了一种基于遥感、气象和水量平衡原理的草原湿地水源涵养评价方法,估算若尔盖湿地近23年(2000-2022)来的水源涵养量。若尔盖湿地是我国黄河源区的重要水源地,所以本研究以若尔盖湿地的水源涵养功能评估为科学问题,基于遥感数据、GIS数据等,利用水量平衡原理,发展计算简单、便捷、数据易获取的“水源涵养估算方法”,科学估算若尔盖湿地水源涵养服务量,探究其时空动态变化趋势及其影响因素;公式中,Z1和Z2为两个不同高度面的高度,u为摩擦速率; 阅读详情

相关推荐

python实现语音信号的分帧、加窗、预处理

语音信号实现分帧、加窗、预处理音频文件读取预加重分帧加窗 音频文件读取 librosa是非常强大的python语音信号处理库。 读取音频: 使用语句librosa.load(path, sr=22050, mono=True, offset=0.0, duration=None)读取音频文件,默认的采样率是22050,若要保留音频的原始采样率,使用sr=None。 其中: path:表示音频文件的路径 sr:表示采样率 mono:bool,是布尔类型,表示是否将信号转换为单声道 offset:float,后

weixin_45272908的博客 1万+

IOS开发 REST请求 ASIHTTPRequest用法

  ASIHTTPRequest类库简介和使用说明 官方网站: http://allseeing-i.com/ASIHTTPRequest/ 。可以从上面下载到最新源码,以及获取到相关的资料。 使用iOS SDK中的HTTP网络请求API,相当的复杂,调用很繁琐,ASIHTTPRequest就是一个对CFNetwork API进行了封装,并且使用起来非常简单的一套API,用Obj...

yihaoxue的博客 381

海康工业相机 Could not find module MvCameraControl.dll(已解决)

【代码】海康摄像机 Could not find module MvCameraControl.dll(已解决)

hmbbpdx的博客 2224

关于AFNetworking设置Content-Type,请求头

服务器那边不知道怎么调,自己对于服务器不懂,给我的要求是在请求(POST)时,content-Type要求是html,然后参数(AFN中就是parameters)要求是json格式.... AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.r

YZ_boy的博客 2万+

uniCloud云存储进阶:七牛云扩展存储从开通、绑定域名到批量上传的完整实战

本文详细介绍了uniCloud云存储进阶实践,重点讲解如何通过七牛云扩展存储实现从开通、绑定域名到批量上传的完整流程。内容涵盖成本优势分析、域名备案方案、SSL证书配置、多文件并发上传控制等实战技巧,并提供可直接复用的代码示例,帮助开发者高效构建内容社区类应用。

weixin_26985923的博客 468

用 Python 和 uiautomation 实现微信批量发送

思路是这样,将要发送的人员名单(包括称呼)以及发送内容都维护到Excel里,程序运行时读取Excel里内容,自动搜索人员姓名(微信昵称或备注名),填入要发送的内容,拼接上称呼(如果需要的话)自动点击发送,这样轮巡直至名单人员全部发送完成。、

jankingdom的专栏 1471

ASI框架设置Content-Type无效的问题

我服务器的某些接口只接收Content-Type 为“application/x-protobuf”的访问,我是用ASIFormDataRequest向服务器发送数据,通过addRequestHeader:value:方法设置Content-Type,结果总是不成功,在服务器端发现收到的Content-Type为“application/octet-stream”,后来经过多番尝试,通过使用set

fangzhangsc2006的专栏 2808

QT绘制饼图+柱状图+折线图

使用qt绘制,折线图,饼图,柱状图,多柱状图

梅山 3878

ASIHTTPRequest的使用—— ASIDownloadCache缓存

ASIDownloadCache 设置下载缓存 它对Get请求的响应数据进行缓存(被缓存的数据必需是成功的200请求): [ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]]; 当设置缓存策略后,所有的请求都被自动的缓存起来。 另外,如果仅仅希望某次请求使用缓存操作,也可以这样使用: ASIHTTPRequest

番薯大佬的专栏 1016

AI虚拟人物 数字人直播,不用出镜,不用露脸的直播方式(附教程 软件)

我们先来看一组数据,这是我通过蝉妈妈查到的某位虚拟主播的一个带货数据,粉丝还不到 3000 人,每次直播 1 到 4 个小时,30天的总销量达到了1200单,15天,总销售额 2 万,可能相对来说客单价还是比较低,最关键的是才直播了 6 场,如果说他能够一个月直播 20 天,每天花 4个小时去直播,当个副业来做,就可以达到最起码月入 3 万的一个收入水平,我个人觉得是非常的不错的。大家把商品图片放在背景,只要场景设置的不错,场景和产品的关联度高,直播的时候挂上购买链接也会有一定的成交。

. 7万+

YOLO26改进策略【卷积层】| SPD-Conv 针对小目标和低分辨率图像的检测任务

SPD-Conv是一种新的 CNN 构建模块,用于替代传统 CNN 架构中使用的步长卷积(strided convolution)和池化(pooling)层,它由空间到深度(Space-to-depth,SPD)层和非步长卷积(non - strided convolution)层组成。

Limiiiing的博客 359

ASIHttpRequest 本地缓存

于是我从网上查阅了相关的资料,发现总体上说有两种方法。一种是自己写缓存的处理,一种是采用ASIHTTPRequest中的ASIDownloadCache。根据自己目前的水平,我选择后者,具体的实现方法:  1、设置全局的Cache     在AppDelegate.h中添加一个全局变量 @interface AppDelegate : UIResponder   {

努力~ 997

华为OD机试双机位C卷-组装新的数组(Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【组装新的数组】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 组装新的数组。

qq_45776114的博客 1145

ASIHTTPRequest 缓存

大文件断点续传 0.94以后支持大文件的断点下载,只需要设置: [ request setAllowResumeForFileDownloads:YES ]; [ request setDownloadDestinationPath:downloadPath ]; 就可以了。 ASIHTTPRequest会自动保存访问过的URL信息,并备之后用。在以下几个场景非常有用: 1,...

移动编程 199

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ASIHttprequest使用详解

大文件断点续传 0.94以后支持大文件的断点下载,只需要设置: [ request setAllowResumeForFileDownloads:YES ]; [ request setDownloadDestinationPath:downloadPath ]; 就可以了。 ASIHTTPRequest会自动保存访问过的URL信息,并备之后用。在以下几个场景非常有用: 1,当

SpeedBoy007的专栏 788

IOS开发网络加载图片缓存策略之──ASIDownloadCache缓存策略

在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用户体验,为了不是每次显示都需要从网上下载数据,希望将图片放到本地缓存,因此我们需要一个好的的缓存策略,今天我将我在项目工程中的实际经验分享给大家,我这里主要介绍一下强大的ASIHTTPRequest的缓存策略,以及使用方法:       下面是具体步骤:     一、

iOS技术分享与学习博客 436

[IOS]ASIHTTPRequest 缓存

ASIHTTPRequest 缓存 转入地址:http://www.07net01.com/program/159527.html 注明本文是根据官方文档进行的翻译,为加深自己理解所做。建议大家还是去看文档比较好,我也是因为时间太紧,所以想短时间内掌握而没有全面的阅读文档,导致今天被卡在一处良久。问了许多人,结果可能是使用版本不同得到许多不同答案,浪费了不少时间,所以建议大

Gamin 963

使用ASIHTTPRequest和ASIDownloadCache实现本地缓存

iPhone开发笔记(16)使用ASIHTTPRequest和ASIDownloadCache实现本地缓存 2012-09-18      0 个评论       作者:kbawyg 收藏    我要投稿     为了节约流量,同时也是为了更好的用户体验,目前很多应用都使用本地缓存机制,其中以网易新闻的缓存功能最为出色。我自己的应用也想加入本地缓存的功能,于是我从网上

iOS技术分享与学习博客 397

ASIHTTPRequest的使用——下载缓存

asi中下载缓存第一种方法 #import #import "ASIHTTPRequest.h" #import "ASIDownloadCache.h" @interface ViewController : UIViewController - (IBAction)click:(id)sender; @property (retain, nonatomic) IBOutl

番薯大佬的专栏 627

iOS缓存策略

需要注意的是,要做缓存的Http请求必须用get方法来获取数据。 1、设置全局的Cache     在AppDelegate.h中添加一个全局变量 @interface AppDelegate : UIResponder { ASIDownloadCache *myCache; } @property (strong, nonatomic) UIWindow *wi

iOS-董彬的专栏 1717

ios中UIWebview和asiHttprequest的用法

原文地址为:http://www.cnblogs.com/pengyingh/articles/2343062.htmlasiHttprequest的用法 它对Get请求的响应数据进行缓存(被缓存的数据必需是成功的200请求): ASIHTTPRequest会自动保存访问过的URL信息,并备之后用。在以下几个场景非常有用: 1,当没有网络连接的时候。 2,已下载的数据再次请求时,仅当...

weixin_34349320的博客 81

ASIDownloadCache 设置下载缓存

ASIDownloadCache 设置下载缓存 它对Get请求的响应数据进行缓存(被缓存的数据必需是成功的200请求): [ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];//类方法调用  所有的请求都会被自动缓存 当设置缓存策略后,所有的请求都被自动的缓存起来。

iOS技术分享与学习博客 367

ios中asihttprequest 下载缓存

asi中下载缓存第一种方法 #import <UIKit/UIKit.h> #import "ASIHTTPRequest.h" #import "ASIDownloadCache.h" @interface ViewController : UIViewController<ASIHTTPRequestDelegate> - (IBAction)click:...

weixin_34405332的博客 77

ASIHTTPRequest缓存

大文件断点续传 0.94以后支持大文件的断点下载,只需要设置: [ request setAllowResumeForFileDownloads:YES ]; [ request setDownloadDestinationPath:downloadPath ]; 就可以了。 ASIHTTPRequest会自动保存访问过的URL信息,并备之后用。在以下几个场景非常有用: 1,当没有网络

slinloss的专栏 426

ASIHTTPRequest和ASIDownloadCache实现本地缓存

为了节约流量,同时也是为了更好的用户体验,目前很多应用都使用本地缓存机制,其中以网易新闻的缓存功能最为出色。我自己的应用也想加入本地缓存的功能,于是我从网上查阅了相关的资料,发现总体上说有两种方法。一种是自己写缓存的处理,一种是采用ASIHTTPRequest中的ASIDownloadCache。根据我目前的技术水平和时间花费,我果断选择了后者,事实证明效果也很不错。下面说一下实现方法:

yuanya的专栏 583
上一篇: iOS6 新增特性
下一篇: Core Data数据持久化的使用
iteye_3205
博客等级 码龄8年 0粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值