标签: nsurlcache

清除NSURLConnection缓存

有没有办法清除NSURLConnection缓存?

我用它来下载一些字符串但我仍然得到相同的字符串,即使我从我的服务器更改了它.

objective-c nsurlconnection nsurlcache ios

26
推荐指数
2
解决办法
2万
查看次数

如何使用NSURLSession和NSURLCache进行缓存.不工作

我有一个测试应用程序设置,即使用户在下载过程中切换应用程序,它也能成功从网络下载内容.太好了,现在我有后台下载了.现在我想添加缓存.没有必要让我多次下载图像,b/c系统设计,给定一个图像URL我可以告诉你该URL后面的内容永远不会改变.所以,现在我想使用Apple内置的内存/磁盘缓存来缓存下载的结果,我已经阅读了很多(而不是我在NSCachesDirectory中手动保存文件,然后在创建之前检查文件)请求,ick).在尝试得到缓存在此工作的代码顶部的工作,我添加以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    // Set app-wide shared cache (first number is megabyte value)
    [NSURLCache setSharedURLCache:[[NSURLCache alloc] initWithMemoryCapacity:60 * 1024 * 1024
                                                                diskCapacity:200 * 1024 * 1024
                                                                    diskPath:nil]];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

当我创建会话时,我添加了两行NEW(URLCache和requestCachePolicy).

// Helper method to get a single session object
- (NSURLSession *)backgroundSession
{
    static NSURLSession *session = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.example.apple-samplecode.SimpleBackgroundTransfer.BackgroundSession"];
        configuration.URLCache = [NSURLCache sharedURLCache]; // NEW LINE …
Run Code Online (Sandbox Code Playgroud)

iphone nsurlcache ios nsurlsession nsurlsessionconfiguration

26
推荐指数
2
解决办法
3万
查看次数

从RestKit过渡到纯AFNetworking 2.0

我过去两年一直在使用RestKit,但最近我开始考虑从这些monolith框架过渡,因为它看起来真的有点过分.

这是我前进的优点:

  1. 使用NSURLSession进行后台提取非常需要,而RestKit只有实验分支用于过渡到AFNetworking 2.0.转换完成后没有实际日期.(主要原因)
  2. 无需网络库中的CoreData支持,因为不需要全功能的离线数据存储.
  3. 令人头疼的是响应/请求描述符的新概念,因为它们不支持路径模式中的不同参数(例如访问令牌参数),并且无法在具有自定义描述符的一行中创建对象请求操作.在这里,我将对象管理器的功能作为外观丢失.

I. 对象映射过程中RestKit的最大损失. 你能推荐你使用的独立库,它们表现出灵活和稳定吗?

II.我很伤心,我不需要功能齐全的存储,但我仍然需要在某些地方提供一些缓存支持.我听说NSURLCache在上一次操作系统发布中变得很有用.你有没有用它,策略是什么?当网络连接断开时,它是否返回缓存的API响应

III.有人面临同样的问题吗?您应用了哪些解决方案?也许有人可以提供一些关于他或她在使用纯AFNetworking的多个应用程序中使用的架构的建议

core-data nsurlcache restkit-0.20 afnetworking-2 nsurlsession

24
推荐指数
1
解决办法
3804
查看次数

防止NSURLSession缓存响应

为什么它会缓存响应.它返回先前获取的响应.它甚至可以在关闭网络连接时工作.重置iOS模拟器似乎也不起作用.提出请求,然后再次使用Internet脱机工作(缓存).

public let urlSession: NSURLSession

public init()
{
    // ...

    var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
    urlSession = NSURLSession(configuration: configuration)
}

func makeRequest(path: String, httpMethod:String, body:String?, baseUrl: String?, headers:[String:String]=[:], callback: JsonRequestCallback)
{
    let urlString = (baseUrl ?? customOAuth2Manager.API_URL) + path
    let url = NSURL(string: urlString)
    let request = oauthInstance.request(forURL: url!)

    request.HTTPMethod = httpMethod
    self.customOAuth2Manager.setupRequest(request)

    for (key, value) in headers {
        request.setValue(value, forHTTPHeaderField:key)
    }

    if let body = body where body != "" {
        let postData = (body as NSString).dataUsingEncoding(NSUTF8StringEncoding) …
Run Code Online (Sandbox Code Playgroud)

caching nsurlcache nsurlsession nsurlsessionconfiguration swift

20
推荐指数
2
解决办法
1万
查看次数

NSURLCache是​​否在发布期间持续存在?

我正在寻找一个适用于我的iOS应用程序的网络缓存解决方案.我开始阅读有关NSURLCache的内容,但没有看到有关持久性的任何提及.当您使用NSURLCache然后关闭并打开应用程序时,是否有人知道这是如何表现的?它会坚持下去吗?

nsurlcache ios

19
推荐指数
1
解决办法
8146
查看次数

如何知道NSURLResponse是否来自缓存?

我在特定文件夹上设置了NSURLCache(../../Application Support/Offline,因此它不会被OS随机删除),然后我发送NSURLRequest和NSURLRequestReturnCacheDataElseLoad策略.

如何判断由符合NSURLConnectionDelegate的类处理的响应是来自缓存还是来自网络?

nsurlconnection nsurlrequest nsurlcache nsurlconnectiondelegate

18
推荐指数
1
解决办法
2151
查看次数

NSURLCache不会清除iOS8中存储的响应

这是我需要清除缓存并对URL进行新调用时调用的示例函数

- (void)clearDataFromNSURLCache:(NSString *)urlString
{
    NSURL *requestUrl = [NSURL URLWithString:urlString];
    NSURLRequest *dataUrlRequest = [NSURLRequest requestWithURL: requestUrl];

    NSURLCache * cache =[NSURLCache sharedURLCache];


    NSCachedURLResponse* cacheResponse =[cache cachedResponseForRequest:dataUrlRequest];

    if (cacheResponse) {
        NSString* dataStr = [NSString stringWithUTF8String:[[cacheResponse data] bytes]];
        NSLog(@"data str r= %@",dataStr);
        NSLog(@"url  str r= %@",[[[cacheResponse response] URL] absoluteString]);
        [cache storeCachedResponse:nil forRequest:dataUrlRequest];
        [NSURLCache setSharedURLCache:cache];
    }

    [[NSURLCache sharedURLCache] removeCachedResponseForRequest:dataUrlRequest];

    //Check if the respnase data has been removed/deleted from cache
    NSURLRequest *finalRequestUrlRequest = [NSURLRequest requestWithURL:requestUrl];
    NSURLCache * finalCache =[NSURLCache sharedURLCache];

    NSCachedURLResponse* finalcacheResponse =[finalCache cachedResponseForRequest:finalRequestUrlRequest];

    if …
Run Code Online (Sandbox Code Playgroud)

caching objective-c nsurlcache ios ios8

17
推荐指数
1
解决办法
4839
查看次数

如何在swift 3中设置共享URLCache?

这是我们在Swift 2中的代码.什么是Swift 3版本?我没有看到setShared的替代品.

let sharedCache: NSURLCache = NSURLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
NSURLCache.setSharedURLCache(sharedCache)
Run Code Online (Sandbox Code Playgroud)

nsurlcache swift3

16
推荐指数
2
解决办法
8008
查看次数

NSURLCache和ETags

是否NSURLCache透明地处理服务器收到的ETag?

我的意思是:它是否自动存储每个URL请求的ETag,然后在If-None-Match提交相同URL的请求时发送适当的?或者我必须自己管理它?

etag nsurlcache ios

15
推荐指数
1
解决办法
6267
查看次数

删除UIWebView的内部缓存

我正在展示一个网络应用程序UIWebView,有时页面内容会发生变化.更改内容后,应用程序将清除缓存.但是当我去一个我以前访问过的页面时,UIWebView它不发送HTTP GET请求,但是从缓存加载,即使我已经禁用了缓存,如下所示:

[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
Run Code Online (Sandbox Code Playgroud)

最初我正在使用cachePolicy加载请求cachePolicy:NSURLRequestReturnCacheDataElseLoad.

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:myURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0]];
Run Code Online (Sandbox Code Playgroud)

UIWebView有某种内部缓存.已访问的页面将从此内部缓存加载而不是通过NSURLCache,也没有发送请求.

有没有办法清除内部缓存UIWebView?我甚至正在重新创建,UIWebView但缓存仍在那里.

cocoa-touch caching uiwebview nsurlcache ios

14
推荐指数
2
解决办法
2万
查看次数