• 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: Progmatically Caching Objects from a CoreData SQLite Store?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Progmatically Caching Objects from a CoreData SQLite Store?


  • Subject: Re: Progmatically Caching Objects from a CoreData SQLite Store?
  • From: Bill Bumgarner <email@hidden>
  • Date: Fri, 24 Feb 2006 13:45:20 -0800

On Feb 24, 2006, at 1:16 PM, Colin Cornaby wrote:
I'm working with an extremely large CoreData database, containing at present 8120 managed objects. It's currently a SQLite store, except I would like to have the entire object tree available in memory for access in order to speed up the user experience. I was thinking I could do something like spawn a thread on launch that goes through and loads pieces of the object tree into memory, allowing the user to continue using the application and work with the on drive store, while working with objects in memory as they become available in memory.

10,000 objects is considered to be a pretty small dataset in the database world. Unless your objects have really large chunks of binary data stored within, 8,120 objects should be quite quick to work with. SQLite can scale to terabyte sized databases with billions of rows/tables/columns.


Given the size of the data set and the desire to work with it in memory, I would suggest simply fetching all the objects into memory at once. This could be done with a single fetch request in the main thread. If that proves to be too time consuming, then move it to a separate object context (against the same store) in a background thread and then pass the objects into the main thread via their global ID, as needed.

See the archives for numerous discussions of threaded Core Data apps.

However, don't bother with threads until you have:

- proven that performance with your data set is a problem in a single threaded app

- optimized your data model

I'm assuming CoreData caches objects in memory as they're accessed and writes back to drive as needed, but it seems to me if this caching does exist the objects don't seem to be cached for the entire lifespan of the application.

It caches objects in memory as they are accessed or fetched, including "faulting in" objects on the other side of relationships. Objects may or may not be cached for the lifetime of the app depending on usage patterns. API is available for optimizing the caching patterns and pruning object graphs.


Does anyone know of a good way to build a cache in memory of an on disk store? Creating an in memory store and copying each object in one by one seems like an awful way to do it. Attempting to add an in memory store to the persistent store coordinator just seems to raise issues when I try to save. So I'm just looking for general pointers on how maybe other people have dealt with this issue.

I would suggest reviewing the Core Data documentation, concept guides and examples. Core Data is designed to manage the in memory cache vs. on disk store extremely efficiently. Certainly, as a generalized implementation, there will be specific usage patterns that are sub-optimal, but that is relatively rare and can often be addressed through changes, often minor, to the object model.


b.bum

_______________________________________________
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


  • Follow-Ups:
    • Re: Progmatically Caching Objects from a CoreData SQLite Store?
      • From: Colin Cornaby <email@hidden>
References: 
 >Progmatically Caching Objects from a CoreData SQLite Store? (From: Colin Cornaby <email@hidden>)

  • Prev by Date: Progmatically Caching Objects from a CoreData SQLite Store?
  • Next by Date: Re: Progmatically Caching Objects from a CoreData SQLite Store?
  • Previous by thread: Progmatically Caching Objects from a CoreData SQLite Store?
  • Next by thread: Re: Progmatically Caching Objects from a CoreData SQLite Store?
  • Index(es):
    • Date
    • Thread