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.

154 questions
2
votes
1 answer

NSCache releases objects even when there are strong references to them?

I've setup a basic NSCache and am storing NSObject subclassed objects. I'm observing these objects being released from the cache (upon backgrounding the app) even when there are 1+ other strong references to them (verified with memory debugger). Am…
Warpling
  • 2,024
  • 2
  • 22
  • 38
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

Swift Get Keys and Values from NSCache

I have an NS Cache, and I would like to get ALL of the objects that it stores as an array. The keys will be needed as well. Everything I have read says that I should be able to basically treat it like a dictionary, but I get compiler errors when I…
Mizmor
  • 1,391
  • 6
  • 21
  • 43
2
votes
4 answers

Cells reload wrong images when scrolled in UI Collection View

I'm downloading images using DropBox's API and displaying them in a Collection View. When the user scrolls, the image either disappears from the cell and another is loaded or a new image is reloaded and replaces the image in the cell. How can I…
user7139248
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
  • 10,918
  • 12
  • 76
  • 110
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,784
  • 9
  • 33
  • 39
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
  • 22,115
  • 10
  • 72
  • 85
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
  • 8,288
  • 6
  • 45
  • 87
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
  • 607
  • 5
  • 15
  • 29
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
  • 317
  • 1
  • 2
  • 17
2
votes
3 answers

Right place to store the application data in IOS

Currently i was saving my application data (Media) to the CacheDirectory i.e /var/mobile/Applications/BEAFC76C-C450-4A3A-9765-A0385A9580F3/Library/Caches and things were going fine. But recently i got a bug report that the application data has…
Nikhil Lihla
  • 607
  • 6
  • 21
2
votes
2 answers

Best image caching strategy in iOS

In my app, I have a UITableView which displays fairly large images and loads a moderately designed Xib file to display it in. Each image is around 700KB to 1MB in size. The flow is virtually never ending, it loads more and more as we scroll down. So…
Rameez Hussain
  • 6,414
  • 10
  • 56
  • 85
2
votes
1 answer

Calling NSCashe doesn't work

I don't know how to use NSCashe but I have tried it after reading this topic How to use NSCache but it didn't work. I am getting this issue reason: '-[NSCache setObject:forKey:cost:]: attempt to insert nil value (key: indexPath)' Am I doing…
Luai Kalkatawi
  • 1,492
  • 5
  • 25
  • 51
2
votes
1 answer

NSCache crashing app

My iOS app project keeps crashing when using NSCache with the console saying *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCache setObject:forKey:cost:]: attempt to insert nil value (key:…
Evilelement
  • 109
  • 3
  • 11
2
votes
1 answer

Can I trust objectForKey right after setObject in NSCache?

Considering this sample code (cache is an instance of NSCache): - (id)objFromCache { if ([cache objectForKey:@"myObject"] == nil) [cache setObject:[self generateObject] forKey:@"myObject"]; return [cache…
diegotrevisan
  • 499
  • 4
  • 14