nscache

NSCache and background

℡╲_俬逩灬. 提交于 2019-11-29 08:01:43
问题 I've noticed that NSCache evicts all of its object when the application goes in background. is that the expected behaviour? is there a way to avoid it? I would expect it to evict objects when the device run out of memory not immediately when the app goes in background. Do you know any valid alternative? 回答1: In my case, that happened when objects stored in NSCache does not conform to NSDiscardableContent protocol. When I added the said protocol, eviction of objects when the app is entering

NSCache is not evicting data

别说谁变了你拦得住时间么 提交于 2019-11-28 20:49:33
NSCache is a rarely used tool which actually looks quite useful. I created a simple experiment to see how it works and it looks like it does not auto-evict data in low memory situations (or I am doing something wrong!) - (void)viewDidLoad { _testCache = [[NSCache alloc] init]; // Allocate 600 MB of zeros and save to NSCache NSMutableData* largeData = [[NSMutableData alloc] init]; [largeData setLength:1024 * 1024 * 600]; [_testCache setObject:largeData forKey:@"original_Data"]; } - (IBAction)buttonWasTapped:(id)sender { // Allocate & save to cache 300 MB each time the button is pressed

What is the proper way to use NSCache with dispatch_async in a reusable table cell?

五迷三道 提交于 2019-11-28 18:27:05
I have been looking for a clear cut way to do this and have not found anywhere that will give an example and explain it very well. I hope you can help me out. Here is my code that I am using: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"NewsCell"; NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... NewsItem *item = [newsItemsArray objectAtIndex:indexPath.row]; cell.newsTitle.text = item.title; NSCache *cache = [_cachedImages objectAtIndex:indexPath

iOS - Best practice to save Images locally - NSCache vs Save in Document Directory

老子叫甜甜 提交于 2019-11-28 16:52:38
问题 I'm developing an app that similar to Instagram feed (tableviews with cells that contain images and some labels). For all the data I'm getting from the database, I'm using Data Task (because it doesn't take much to receive them), but for the images (which their url's I get with the Data request), I need to save locally for future use (improve user experience). My logic is the following: Save in NSCache or in Document Directory, the images inside folder with the date they been downloaded

Save NSCache Contents to Disk

帅比萌擦擦* 提交于 2019-11-28 09:52:44
I'm writing an app that needs to keep an in-memory cache of a bunch of objects, but that doesn't get out of hand so I'm planning on using NSCache to store it all. Looks like it will take care of purging and such for me, which is fantastic. I'd also like to persist the cache between launches, so I need to write the cache data to disk. Is there an easy way to save the NSCache contents to a plist or something? Are there perhaps better ways to accomplish this using something other than NSCache? This app will be on the iPhone, so I'll need only classes that are available in iOS 4+ and not just OS X

Download and cache images in UITableViewCell

我怕爱的太早我们不能终老 提交于 2019-11-28 00:30:26
Note: Please no libraries. This is important for me to learn. Also, there are a variety of answers on this but none that I found solves the issue nicely. Please don't mark as duplicate. Thanks in advance! The problem I have is that if you scroll really fast in the table, you will see old images and flickering. The solution from the questions I read is to cancel the URLSession data request. But I do not know how to do that at the correct place and time. There might be other solutions but not sure. This is what I have so far: Image cache class class Cache { static let shared = Cache() private

NSCache is not evicting data

雨燕双飞 提交于 2019-11-27 13:25:52
问题 NSCache is a rarely used tool which actually looks quite useful. I created a simple experiment to see how it works and it looks like it does not auto-evict data in low memory situations (or I am doing something wrong!) - (void)viewDidLoad { _testCache = [[NSCache alloc] init]; // Allocate 600 MB of zeros and save to NSCache NSMutableData* largeData = [[NSMutableData alloc] init]; [largeData setLength:1024 * 1024 * 600]; [_testCache setObject:largeData forKey:@"original_Data"]; } - (IBAction

What is the proper way to use NSCache with dispatch_async in a reusable table cell?

痴心易碎 提交于 2019-11-27 11:21:23
问题 I have been looking for a clear cut way to do this and have not found anywhere that will give an example and explain it very well. I hope you can help me out. Here is my code that I am using: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"NewsCell"; NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... NewsItem *item = [newsItemsArray objectAtIndex

Save NSCache Contents to Disk

a 夏天 提交于 2019-11-27 03:21:25
问题 I'm writing an app that needs to keep an in-memory cache of a bunch of objects, but that doesn't get out of hand so I'm planning on using NSCache to store it all. Looks like it will take care of purging and such for me, which is fantastic. I'd also like to persist the cache between launches, so I need to write the cache data to disk. Is there an easy way to save the NSCache contents to a plist or something? Are there perhaps better ways to accomplish this using something other than NSCache?

How to use NSCache

…衆ロ難τιáo~ 提交于 2019-11-26 19:22:12
Can someone give an example on how to use NSCache to cache a string? Or anyone has a link to a good explanation? I can't seem to find any.. You use it the same way you would use NSMutableDictionary . The difference is that when NSCache detects excessive memory pressure (i.e. it's caching too many values) it will release some of those values to make room. If you can recreate those values at runtime (by downloading from the Internet, by doing calculations, whatever) then NSCache may suit your needs. If the data cannot be recreated (e.g. it's user input, it is time-sensitive, etc.) then you