Reputation: 38213
I want to save / load instances of my classes using NSCoding. Each class should have an individual cache time / time to live. When the app starts up I want the instance of my class to be either loaded from cache if its not expired or otherwise created normally.
This problem must have been solved hundreds of times....
Is there a good framework for doing this, or should I roll my own?
Upvotes: 1
Views: 352
Reputation: 9481
maybe you can try NSCache NSCache doesn't conform to the NSCoding protocol so you can't archive / unarchive the cache.
An NSCache object is a collection-like container, or cache, that stores key-value pairs, similar to the NSDictionary class. Developers often incorporate caches to temporarily store objects with transient data that are expensive to create. Reusing these objects can provide performance benefits, because their values do not have to be recalculated. However, the objects are not critical to the application and can be discarded if memory is tight. If discarded, their values will have to be recomputed again when needed.
Upvotes: 2
Reputation: 90551
To be clear, you can save or loading objects, not classes, using NSCoding
.
I'm not aware of a framework that does this. You can either use the file modification time as the cache time or you can keep it in a separate database. If it's not too many different classes, you can use NSUserDefaults
as that separate database. Each class would just be coded to know its own time to live.
Upvotes: 1