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
122
votes
5 answers

How to use NSCache

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..
Thizzer
  • 14,949
  • 26
  • 90
  • 134
16
votes
1 answer

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

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…
Jackky White
  • 297
  • 1
  • 4
  • 11
15
votes
4 answers

Save NSCache Contents to Disk

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…
Cory Imdieke
  • 12,771
  • 8
  • 34
  • 46
14
votes
3 answers

NSCache and background

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…
Luka
  • 1,421
  • 4
  • 19
  • 36
11
votes
2 answers

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

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…
mcphersonjr
  • 715
  • 11
  • 32
11
votes
3 answers

NSCache is not evicting data

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 { …
Robert
  • 35,442
  • 34
  • 158
  • 205
9
votes
1 answer

NSCache emptied when app enters background

I currently use a Subclass of NSCache to store some images (values) with their corresponding names (Keys) and it seems to work fine, when the app is in the foreground. However, when I press the home button/the user enters the background and I…
Kevin Wu
  • 1,117
  • 1
  • 12
  • 30
9
votes
2 answers

NSCache crashing when memory limit is reached (only on iOS 7)

We are using NSCache for UIImages in our app. This works fine on iOS versions smaller than 7. When a memory warning occurs, NSCache releases objects as intended. However, on iOS 7, our app crashes shortly after the first memory warning. So it seems…
Flo
  • 2,089
  • 16
  • 23
9
votes
1 answer

How to iterate over NSCache keys

I need to make a dictionary like NSCache which is thread-safe for keeping a cahce. However, once in a while, I would need to refresh the contents of the Cache. NSCache does not provide a method to iterate over its keys. What would be the alternative…
Ali
  • 1,393
  • 2
  • 13
  • 19
8
votes
3 answers

NSCache is always evicting image data when app enters background

This might be the expected behavior, but is not clearly stated by Apple. I am using NSCache to cache some images for my UICollectionView. When I put the app in the background and open it again (immediately), all of my images are no longer in the…
chrysb
  • 637
  • 6
  • 15
8
votes
2 answers

NSCache: Always getting "not key value coding-compliant" when trying to access cached item

I'm attempting to use NSCache to store PNGs as NSData. Whenever I try to get one back out of the cache, whether the cache is empty or not, I get: 2012-10-26 09:49:28.860 SledMap[55917:11503] * Terminating app due to uncaught exception…
Ryan Quick
  • 103
  • 3
8
votes
1 answer

Objective-c - benefits of using NSCache over a static NSMutableDictionary?

So the NSCache object should stay alive in order to keep the cached data, that means the same object that was used to store data, has to be used to retrieve data. So the question is what's the point of using NSCache over a singleton NSDictionary…
aryaxt
  • 69,636
  • 87
  • 281
  • 421
7
votes
2 answers

How to store data in NSCache in ios?

I am very new to NSCache. I have an API call which results in several objects.How to store these objects in NSCache so that I don't require to call the API again. How much data can be stored in NSCache. Is there a specific limit to store the data in…
Aswathy Bose
  • 4,209
  • 4
  • 30
  • 43
6
votes
2 answers

How to approach 'caching' in iOS development with Swift

I am facing some issues in terms of what caching mechanism to implement for my iOS application. First, lets explain my situation. I want to request thousands of nearby locations records (10000 and more) through a RESTful API on my server using…
arauter
  • 5,333
  • 3
  • 24
  • 28
6
votes
3 answers

Need to save and retrive UIImages using buffer

My application is a kind of picture gallery. when ever user clicks on icon in the gallery, need to display the images( Landscape 2 images , portrait 1 image). The pictures may be more than 100. I usually take raw file and decode into UIImage format.…
Kiran Kumar
  • 677
  • 3
  • 16
1
2 3
9 10