Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restkit, disable caching

Tags:

ios

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?

like image 365
Gael.D Avatar asked Feb 27 '12 10:02

Gael.D


1 Answers

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;

Was that what you were doing?

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.

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 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).

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.

like image 166
drewish Avatar answered Sep 20 '22 14:09

drewish