10

I am using RestKit for webservice calls, caching, and etags. I implemented my own coredata model and managedObjects

As soon as the user signs out I need to clear all data in the database. I was able to successfully delete the sqlite file and recreate it, but I can't find out a way to clear all RestKit catching and etag data. How can I completely wipe all data stored by RestKit?

aryaxt
  • 76,198
  • 92
  • 293
  • 442

4 Answers4

14

You want to call [[RKClient sharedClient].requestCache invalidateAll]; to wipe the cache clean. You can view the API docs.

drewish
  • 9,042
  • 9
  • 38
  • 51
Blake Watters
  • 6,607
  • 1
  • 43
  • 33
4

Use the following method from the RKManagedObjectStore class.

- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

http://restkit.org/api/0.9/Classes/RKManagedObjectStore.html#//api/name/deletePersistantStoreUsingSeedDatabaseName:

Paul Ardeleanu
  • 6,620
  • 2
  • 40
  • 41
  • what would be my seed file? I have my own core data model and context, I don't use restkit for that – aryaxt Aug 26 '11 at 21:33
  • 1
    In that case your question was answered here: http://stackoverflow.com/questions/1077810/delete-reset-all-entries-in-core-data – Paul Ardeleanu Aug 27 '11 at 10:56
  • I don't think they store cache and etags in the same sqlite file. Currently I delete my sqlite and recreate it and when I call the webservice, RestKit returns the previous cached data, so I end up with my old data again. – aryaxt Aug 28 '11 at 21:21
2

In Restkit 0.20 try this:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

worked for me =)

Lucas Torquato
  • 407
  • 4
  • 8
1

In RestKit 0.20.2 the following example does the trick. Its based off code found in the RestKit/Testing component in the file RKTestFactory.m and has worked great in my project.

Also, If RestKit is managing your CoreData stack, which is how mine is set up, remember to delete any NSFetchedResultsController that are using the NSManagedObjectContext in your RestKit setup.

- (void)tearDownRestKit
{
    // Cancel any network operations and clear the cache
    [[RKObjectManager sharedManager].operationQueue cancelAllOperations];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];

    // Cancel any object mapping in the response mapping queue
    [[RKObjectRequestOperation responseMappingQueue] cancelAllOperations];

    // Ensure the existing defaultStore is shut down
    [[NSNotificationCenter defaultCenter] removeObserver:[RKManagedObjectStore defaultStore]];

    // Not be needed if not using indexer
    if ([[RKManagedObjectStore defaultStore] respondsToSelector:@selector(stopIndexingPersistentStoreManagedObjectContext)]) {
        // Search component is optional
        [[RKManagedObjectStore defaultStore] performSelector:@selector(stopIndexingPersistentStoreManagedObjectContext)];

        if ([[RKManagedObjectStore defaultStore] respondsToSelector:@selector(searchIndexer)]) {
            id searchIndexer = [[RKManagedObjectStore defaultStore] valueForKey:@"searchIndexer"];
            [searchIndexer performSelector:@selector(cancelAllIndexingOperations)];
        }
    }

    [RKObjectManager setSharedManager:nil];
    [RKManagedObjectStore setDefaultStore:nil];
}
JohnO
  • 41
  • 2