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
7
votes
4 answers

Inspect NSCache contents on iOS?

Is there a way to inspect NSCache's contents for debugging purposes? This would not be used in the App Store. I just would like to be able to see what's going on in there while debugging. The description is pretty useless.
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
7
votes
1 answer

Empty the cache programmatically in iOS

Does anyone by coincidence know how I can empty the cache memory of the iOS app that I am developing, in the moment it goes to the background (applicationDidEnterBackground)? I have investigated about NSCache but I am still not able to understand…
Stefan S
  • 267
  • 2
  • 6
  • 12
7
votes
2 answers

Use a global NSCache or one per class?

I'm wondering if it's better to use one global instance of NSCache or several ones for each component that need it. For example, I have several view subclasses that draw content into images and cache them to avoid regenerating them all the time. Is…
Olivier
  • 387
  • 1
  • 9
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,279
  • 4
  • 32
  • 44
6
votes
1 answer

Set UIImage to UIImageView directly with kingfisher

I want to setImage with UIImage directly and not from any Source, Resource. I already have my image and want to set it with caching to my imageView. let myImage = UIImage kingfisherView.kf.setImage(with: myImage) i want this to be done like i set…
Deepak Verma
  • 373
  • 7
  • 19
6
votes
2 answers

Download and cache images in UITableViewCell

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…
JEL
  • 1,540
  • 4
  • 23
  • 51
6
votes
1 answer

How to clear cached data stored by URLSession/URLConfiguration?

I am using the code below to set the caching policy of my URLSession via URLConfiguration. if appDelegateObj.configuration == nil { appDelegateObj.configuration = URLSessionConfiguration.default } if self.apiType ==…
Umar Farooque
  • 2,049
  • 21
  • 32
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
  • 17
6
votes
2 answers

Achieve smooth scrolling for Photo Grid with thousands of images from disc

I have a PhotoGrid with three photos on each row, implemented using UITableView. I have an in-memory cache (using NSCache) which has a capacity for 100 images, so at one time I will be having at most 100 images in memory even though I have thousands…
Jai V
  • 61
  • 3
5
votes
3 answers

NSCache Doesn't work with all images when loading for the first time

I'm woking on a project in swift 3.0 where I cache the response from the server by using NSCache as to populate them in a UITableView. However for some reason I'm only seeing few images loading when the app loads for the first time, but if If i…
danu
  • 1,079
  • 5
  • 16
  • 48
5
votes
1 answer

When I use NSCachedURLResponse,I got "301PermMove"

when I test NSURLCache,I got "301PermMove",this is my code -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSURL *url = [NSURL URLWithString:@"https://www.github.com"]; NSURLRequest *urlRequest = [[NSURLRequest…
hmxxxhhh
  • 59
  • 4
4
votes
3 answers

Cannot generate Video Thumbnails with Cache in Swift

Been struggling to make it work. I am generating the Video Thumbnails but it's loading really heavily in a collection view. I would like to cache them and I can not find a solution. This is the code I am using: func previewImageFromVideo(url:NSURL)…
Marian Petrisor
  • 262
  • 2
  • 19
4
votes
0 answers

cache array of objects iOS

how can I cache array of objects in iOS using swift 3 ?? I know I can use NSCache for it the only problem is this that I know how to cache a single object but dont know how to cache a whole array of it.. var cachedData = NSCache
user6883365
4
votes
1 answer

iOS - how does NSCache ensure thread safe

I want to implement a thread-safe MutableDataContainer. Of course, I can simply add a lock for writing and reading operation, but in my project, I need to read data frequently, so I don't want to use this approach. Does anyone know how NSCache is…
pingshw
  • 113
  • 2
  • 9
4
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
  • 1,017
  • 1
  • 9
  • 18
1
2
3
10 11