Questions tagged [nscache]

NSCache is a cache-related class included in Apple's Foundation framework.

NSCache is similar to NSMutableDictionary, with the differences being:[1]
1. It is guaranteed to be thread-safe.
2. It is much slower to access.
3. It may throw out objects from time to time. You can set costs and limits, but they're not guaranteed to be followed.
4. It is not toll-free bridged to anything in CoreFoundation.
5. You can't query the number of objects that are in the cache.
6. You can't enumerate a cache.

148 questions
3
votes
0 answers

NSCache with NSDiscardableContent or NSMutableDictionary?

Currently, I'm using NSCache to store data for my app. I can always retrieve that data again from the server, so it is not a problem if I eventually lose the data, that's why I'm using NSCache. The problem is that every time my app enters background…
Jorge
  • 1,482
  • 1
  • 17
  • 33
3
votes
2 answers

When does NSCache release the caches objects?

I have implemented a list where a number of large images are being loaded asynchronously. I am using an instance of NSCache to store these UIImage files. As I scroll down, I load more and more images. I set this up and was profiling the app for…
Rameez Hussain
  • 6,036
  • 9
  • 48
  • 84
3
votes
1 answer

NSCache to store images for UITableView

I have a view controller with a table view. in each cell of the table view, i have an image which is fetched from the net - but many of them have the same image. so, what i'm doing currently is storing the fetched images in a NSCache object. it…
3
votes
1 answer

Does NSCache persist between launches?

I'm looking into a fairly simple mechanism for caching and and currently using NSCache (for the reason of memory management). Question is - does the cache persist between launches? It seems like no to me. I get objects put in cache just fine and can…
Live2Enjoy7
  • 1,075
  • 1
  • 10
  • 22
3
votes
2 answers

Key-Value Observing NSCache

I want to get notified when the object corresponding to a certain key in an NSCache instance changes. I've tried using Key-Value Observing without luck (the console doesn't log anything). - (void)viewDidLoad { [super viewDidLoad]; …
datwelk
  • 962
  • 1
  • 8
  • 20
2
votes
2 answers

How to cache images in Objective-C

I want to create a method to cache an image from an URL, I got the code in Swift since I had used it before, how can I do something similar to this in Objective-C: import UIKit let imageCache: NSCache = NSCache() extension…
2
votes
0 answers

How to cache a file e.g PDFDocument, to prevent re-loading and increase user experience - swift?

I have an app with a collection view that displays thumbnails of pdf documents. When a user taps on the thumbnail a new UIViewController is presented along with the PDFDocument. I am trying to cache the PDFDocument so that the app does not have to…
dean
  • 281
  • 2
  • 13
2
votes
2 answers

NSCache and persistence?

My app performs searches of some items and downloads an image per each result it gets. It shows the results on a tableView, a cell per result, and each cell shows the corresponding image. I'd like to cache the images to avoid being downloading the…
AppsDev
  • 11,441
  • 20
  • 81
  • 163
2
votes
0 answers

What is the safest directory in iOS which can be used to download images/pdfs?

I have used NSCachesDirectory in my iPad App to store images and PDFs. Now, my client's complaint is that he is not able to see downloaded content after few hours of downloading. iPad has iOS 11.2.1. In begging, my thought was that, there may be a…
2
votes
0 answers

Pre-caching views for UICollectionViewController

I am trying to avoid rendering delays in UICollectionViewController by pre-caching subviews of cell contentView in NSCache but it seems I miss to activate them properly since there is a delay in rendering cell when user scrolls to it (scrolling…
Andrei
  • 9,162
  • 7
  • 68
  • 103
2
votes
2 answers

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.
MartinJoo
  • 2,394
  • 8
  • 29
  • 38
2
votes
1 answer

NSCache behaviour with non-object types

The following code works perfectly well, but I am surprised, because I thought NSCache would require object keys & values, and would not take CGFloats. Can someone explain to me what is happening? class A var cachedPoints = NSCache() func…
Grimxn
  • 20,778
  • 9
  • 67
  • 80
2
votes
0 answers

Save responseObject JSON into NSCachedURLResponse for ios?

I am having trouble with saving JSON to NSCachedURLResponse. This is my code: operation.responseSerializer = AFJSONResponseSerializer() operation.setCompletionBlockWithSuccess({ (operation, responseObject) -> Void in var cachedResponse =…
AaoIi
  • 7,995
  • 6
  • 40
  • 81
2
votes
1 answer

NSCache initialization for storing UIImage ios

I am using NSCache to store images. But problem here is once I switch between controllers , NSCache empties. I want the items to be there atleast until application is closed or user logs out . Lets say I have a tab view and I am storing images from…
user2714823
  • 567
  • 4
  • 13
  • 26
2
votes
2 answers

How to use EGOCache to cache and load page faster

I have an UIWebView in my iOS app that loads different url's depending on a previous action. I wan't these pages to load as fast as possible. I found the class EGOCache (source) and I i got it working to store cacheData in library/Caches directory.…
Tibbe
  • 307
  • 1
  • 2
  • 17
1 2
3
9 10