• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData, reset a persistent store
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData, reset a persistent store


  • Subject: Re: CoreData, reset a persistent store
  • From: Pierre Chatelier <email@hidden>
  • Date: Tue, 14 Nov 2006 20:13:53 +0100

You haven't specified the store type you're using, whether your app is document-based, or the amount of data you're working with and how it's structured. If you post this information, you might get a clearer answer or a better suggestion.
You are right. I thought that it was only a little question, with an answer like "you're right" or "you're wrong, just do that <snip>", but it seems debatable :-)

So, here are more informations :

-I have an application that computes some data. Each computed data is put inside an object that has some attributes : the data, the options used for computation... The data makes it a large structure, but it is a simple one : there is no relationship properties in the class, only attributes.

-Now, I want to cache the data that is computed, for later use in the same application. ("Later" means some other day, the life time is greater that the application run-time). CoreData with SQLLiteStore is of great help, since it allows to store much data, but to keep in memory only what is necessary.

-So, I have a very simple data model that holds only one entity : an NSManagedObject with the attributes described above (data, options...), and I can request the NSManageObjectContext to load some cached object instead of computing the data again.

-Now, I want to let the user free the cache directly from a menu of the application. The user may want to do that to save some space on its disk, or to force triggering computations again instead of using cached values (let's say for benchmarking or debbugging). Depending on the user and the way he's using the application, the cache file may be from some mega-bytes to some giga-bytes.

-So, to delete the cache, I was expecting a way to tell the NSManagedObjectModel : "ok, forget all". But it does not empty the file under the NSPersistentStoreCoordinator ! So I have to do that myself. A simple way is to fetch all objects, remove them and save, but this is a pain to load all that data in memory, for nothing !
So far, what I do is:
-lock the managed object context
-reset the managed object context to clear all pending changes
-call removePersistentStore:error on the PersistentStoreCoordinator
-remove the underlying file with NSFileManager
-call addPersistentStoreWithType:configuration:URL:options:error on the PersistentStoreCoordinator to re-create the file
-unlock the managed object context
this is simple, it works, but I personnally find it strange that the API cannot do that for me. The API could do even better, it could delete all objects of my NSManagedObjectModel (even if they are faults), in every persistent store attached to that model.


Fair enough, but I consider memory consumption / paging a pretty significant part of 'performance'.
Ok

Then again, the documentation does say, "... although of course reading 1GB of data into memory is an expensive operation no matter how efficient the repository ..."
Yes, so my problem is to avoid loading, since it is totally useless (I just want to delete the data). You can call it optimization, but in this case I think it is just common sense.

I hope this is at least somewhat helpful.
Certainly !

Regards,

Pierre Chatelier

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >CoreData, reset a persistent store (From: Pierre Chatelier <email@hidden>)
 >Re: CoreData, reset a persistent store (From: Elise van Looij <email@hidden>)
 >Re: CoreData, reset a persistent store (From: Pierre Chatelier <email@hidden>)
 >Re: CoreData, reset a persistent store (From: Elise van Looij <email@hidden>)
 >Re: CoreData, reset a persistent store (From: "I. Savant" <email@hidden>)
 >Re: CoreData, reset a persistent store (From: Pierre Chatelier <email@hidden>)
 >Re: CoreData, reset a persistent store (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: CoreData, reset a persistent store
  • Next by Date: Re: Modify view animation while running
  • Previous by thread: Re: CoreData, reset a persistent store
  • Next by thread: Re: CoreData, reset a persistent store
  • Index(es):
    • Date
    • Thread