ios - confusion in data storage into nscache -
i know im doing mistake here coz cant run project im trying build , im trying here parsed data xml save nsdata , put data cache when run project doesnt load data.
@implementation viewcontroller { nscache *mycache; } - (void)viewdidload { mycache = [[nscache alloc] init]; } //saving data cache nsstring *imageurl = [currentdata.imagelink]; nsurl *url = [nsurl urlwithstring:imageurl]; nsdata *data = [nsdata datawithcontentsofurl:url]; data = [imagescache objectforkey:@"key"]; [imagescache setobject:imagelinks forkey:@"key"];
a few things:
- data downloads should done on background thread.
- it's best have own object in cache, , object should download image , cache both image , save image disk. when cache gets purged should remove image , reload disk if required.
this code:
nsdata *data = [nsdata datawithcontentsofurl:url]; data = [imagescache objectforkey:@"key"]; [imagescache setobject:[nsdata datawithcontentsofurl:url] forkey:@"key"];
downloads date, throws away , replaces whatever in cache , updates cache else. should more like:
[imagescache setobject:imagelinks forkey:@"key"];
for point 2 objects should confirm nsdiscardablecontent
.
Comments
Post a Comment