Search code examples
iphoneobjective-ccachingnscache

How to cache data in ios


I loaded XML data (including images, text,...) from server and display that data on iphone screen.

How can i cache data to re-load that screen when i visit that screen other time. It will be faster . (dont need re-load XML data again)?

Thank you.


Solution

  • Use EGOcache API. Just import the EGOCache.h file in your class

    - (void)setObject:(id<NSCoding>)anObject forKey:(NSString*)key;
    -(void)setObject:(id)anObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
    -(id)objectForKey:(NSString*)key;
    

    Use the first method for set your data with a forkey. If you want secify the cache time then use the second method.

    Edit

    EGOCache will save your data permanently, See here to for usage of NSCache which is incorporates various auto-removal policies.