Restkit,禁用缓存 [英] Restkit, disable caching

查看:49
本文介绍了Restkit,禁用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很难尝试在 Restkit 框架中禁用缓存.我尝试将缓存策略设置为无,但完全没有效果.这样做的正确方法是什么?

I've got a really hard time to try disabling caching in the Restkit framework. I've try to put the cache policy to none, with no effect at all. What's the correct way to do this?

推荐答案

所以一旦你有了一个客户端,要么明确地初始化它:

So once you've got a client, either explicitly initializing it:

RKClient *client = [RKClient clientWithBaseURL:url];

或者让对象管理器来做:

or by letting the object manager do it:

RKObjectManager* om = [RKObjectManager managerWithBaseURLString:url];
RKClient *client = om.client;

设置缓存策略应该很简单:

It should be a simple matter of just setting the cache policy:

client.cachePolicy = RKRequestCachePolicyNone;

那是你在做的吗?

更新:由于日志消息是唯一令人担忧的事情,我决定追踪其来源.tl;dr 版本是忽略消息并相信日志代理告诉您的内容.

Update: Since the logging message is the only thing worrying I decided to track down its source. The tl;dr version is to ignore the message and trust what the logging proxy is telling you.

为了仔细检查,我搜索了Invalidating cache at path"并在两个位置找到它RKCache invalidateSubDirectory:RKCache invalidateAll 并在它们上设置断点.这是我的一些代码的部分堆栈跟踪:

To double check I searched for "Invalidating cache at path" and found it in two locations RKCache invalidateSubDirectory: and RKCache invalidateAll and set break points on them. Here's a partial stack trace from some of my code:

#0  0x000e6c66 in -[RKCache invalidateSubDirectory:] at RestKit/Code/Support/RKCache.m:189
#1  0x0006b767 in -[RKRequestCache invalidateWithStoragePolicy:] at RestKit/Code/Network/RKRequestCache.m:237
#2  0x0006b958 in -[RKRequestCache setStoragePolicy:] at RestKit/Code/Network/RKRequestCache.m:253
#3  0x00069abf in -[RKRequestCache initWithPath:storagePolicy:] at RestKit/Code/Network/RKRequestCache.m:60
#4  0x000586f3 in -[RKClient baseURLDidChange:] at RestKit/Code/Network/RKClient.m:339
#5  0x000589ce in -[RKClient observeValueForKeyPath:ofObject:change:context:] at RestKit/Code/Network/RKClient.m:373
#6  0x0183cd91 in NSKeyValueNotifyObserver ()
#7  0x0183c895 in NSKeyValueDidChange ()
#8  0x0182233e in -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] ()
#9  0x01844a82 in _NSSetObjectValueAndNotify ()
#10 0x00057404 in -[RKClient initWithBaseURL:] at RestKit/Code/Network/RKClient.m:176
#11 0x00056df3 in +[RKClient clientWithBaseURL:] at RestKit/Code/Network/RKClient.m:130

我从中了解到的是,有两个枚举控制缓存:

What I learned looking through this is that there are two enums that control caching:

  • RKRequestCachePolicy 这是您在客户端上设置的内容,它控制何时查询缓存.
  • RKRequestCacheStoragePolicy 决定结果在设备上存储多长时间(从不、会话持续时间、永久).
  • RKRequestCachePolicy which is what you set on the client, it controls when the cache is consulted.
  • RKRequestCacheStoragePolicy which determines how long the results are stored on the device (never, duration of session, permanent).

作为设置客户端的一部分,当设置 URL 时,客户端创建一个新的缓存,RKRequestCacheStoragePolicyPermanently 设置存储策略涉及清除以前的会话缓存,如果缓存被禁用——永久缓存.这是您在日志消息中看到的清除.

As part of setting up the client, when a URL is set the client creates a new cache with RKRequestCacheStoragePolicyPermanently setting the storage policy involves clearing out the previous session cache and—if caching is disabled—the permanent cache. It's that clearing that you're seeing in the logging messages.

这篇关于Restkit,禁用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆