I am pulling data from an API and then building out my data objects with it. I want to cache this data for the future. I have been storing the string from the api in NSUserDefaults and then re-parsing it each time the app loads. This works, but it really seems like the wrong way to go about it.
How can I do this?
The NSURLCache class implements the caching of responses to URL load requests, by mapping NSURLRequest objects to NSCachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions.
A mutable collection you use to temporarily store transient key-value pairs that are subject to eviction when resources are low.
In cell phones and networks, a cache usually refers to a memory storage area in the phone or network that stores copies of information that is likely to be needed in the near future, so it can be accessed faster.
Cached data helps apps load faster by keeping temporary files such as thumbnails, scripts, and video snippets on your phone instead of loading them from the web each time. But cached data can quickly fill up your phone's storage.
Have you noticed the NSCache?
An
NSCache
object is a mutable collection that stores key-value pairs, similar to anNSDictionary
object. TheNSCache
class provides a programmatic interface to adding and removing objects and setting eviction policies based on the total cost and number of objects in the cache...
Personally I'm quite fond of the EGOCache classes, I use them quite a lot in my projects:
https://github.com/enormego/EGOCache
The classes are easy to use, I used to have my own classes with a similar design, but these are just more well-rounded, so I decided to stick with them (don't wanna reinvent the wheel).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With