Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C Data Caching on iOS

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?

like image 760
lavoy Avatar asked Apr 20 '11 16:04

lavoy


People also ask

What is NSURLCache?

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.

What is Nscache?

A mutable collection you use to temporarily store transient key-value pairs that are subject to eviction when resources are low.

What is cellular cache?

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.

What cached data?

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.


2 Answers

Have you noticed the NSCache?

An NSCache object is a mutable collection that stores key-value pairs, similar to an NSDictionary object. The NSCache 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...

like image 177
Eric V Avatar answered Sep 19 '22 02:09

Eric V


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).

like image 32
Wolfgang Schreurs Avatar answered Sep 20 '22 02:09

Wolfgang Schreurs