Safe to cache NSManagedObjects in an array?
I have an app that queries the Core Data database for the same couple of objects over and over, sometimes at a pretty high rate.
The database is pretty big but in the most common use case the app require the same set of (about 50 at any given time) objects over and over. There are a lot of different places where the objects are needed so to cater for every possible scenario I must ask for the NSManagedObject I need every time as I could be needing a different object.
To speed things up I have a simple NSMutableArray of 100 length that I use as a FIFO buffer for the NSManagedObjects. Then as I need an object I loop through the array of objects and if the object I'm after is there it is being returned - Otherwise I query the database and add the resulting NSManagedObject to my buffer.
This has sped up my application significantly and I have not had any problems with this in testing but I still wonder if this is safe (and recommended) to do. Is there perhaps already some predefined buffer I should be using? (i.e. am I re-inventing the wheel?)
|