10

Web サービスの呼び出し、キャッシュ、および etag に RestKit を使用しています。独自のコアデータ モデルと managedObjects を実装しました

ユーザーがサインアウトしたらすぐに、データベース内のすべてのデータを消去する必要があります。sqlite ファイルを正常に削除して再作成することはできましたが、RestKit のキャッチ データと etag データをすべてクリアする方法がわかりません。RestKit によって保存されたすべてのデータを完全に消去するにはどうすればよいですか?

4

4 に答える 4

14

[[RKClient sharedClient].requestCache invalidateAll];キャッシュをきれいに消去するために呼び出します。API ドキュメントを表示できます。

于 2011-08-29T12:29:48.817 に答える
4

RKManagedObjectStoreクラスから次のメソッドを使用します。

- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

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

于 2011-08-26T20:40:47.497 に答える
1

RestKit 0.20.2 では、次の例でうまくいきます。ファイル RKTestFactory.m の RestKit/Testing コンポーネントにあるコードに基づいており、私のプロジェクトでうまく機能しています。

また、RestKit が CoreData スタックを管理している場合 (これが私のセットアップ方法です)、RestKit セットアップで NSManagedObjectContext を使用している NSFetchedResultsController を削除することを忘れないでください。

- (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];
}
于 2014-04-11T18:05:25.627 に答える