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

Best way to cache an NSArray of text/dictionaries and have it useable across the entire app?

I am making a request for an array of perhaps 10-100 objects, all of which are JSON objects that I parse into NSDictionary's. I want to cache this and use this data across the entire application. Is NSCache useful for this or is it better to use…
Hudson Buddy
  • 726
  • 2
  • 9
  • 20
2
votes
1 answer

Easiest way to store NSCache full of NSImages

What is the simplest way to persistently store a NSCache filled with NSImages? I'm not looking for Core Data, which seems like overkill for just storing a dictionary with images.
houbysoft
  • 32,532
  • 24
  • 103
  • 156
2
votes
2 answers

Persisting the contents of NSCache

I am using NSCache to store the webData. webData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:urlString]]; [cache setObject:webData forKey:urlString]; The cache will be exist only when my application is running. I want to persist the…
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
1
vote
1 answer

Is UserDefaults a bad practice to cache data?

As a newbie on iOS, I am devoloping a small app. There are 5 different pages and 4 of them has an imageView for user's profile photo, I am storing and downloading profile photo in Firebase. Is it a bad practice to store the profile photo on…
traglen
  • 31
  • 5
1
vote
1 answer

Does the different way of handling key between NSMutableDictionary and NSCache (copy vs. retain) result in different consequence?

I studied the differences between NSMutableDictionary and NSCache. One of them was that NSMutableDictionary copy its keys and NSCache just retain it as a strong reference. In addition, I found that the reason why the key is copied from the…
naljin
  • 439
  • 3
  • 10
1
vote
0 answers

Save images in NSCache after terminating app

I'm currently developing an iOS application where I've a lot of images. I use NSCache() for storing the images. So, every time I load the application the images is being downloaded, saved in cache and stays in the cache all the way till I terminate…
Putte
  • 526
  • 1
  • 6
  • 15
1
vote
0 answers

cache json data from api to use it in table view swift 5

How can I Cache JSON from API ? i Fetch the JSON from the API & Parse the JSON data. These can be done with the help of Alamofire & ObjectMapper and this my way to do this this my request function Alamofire.request(URL(string: baseurl +…
1
vote
2 answers

UIImage keeps loading all time when scroll even store in NSCache - swift

I am new in iOS programming. I am creating a simple app which loads image from a particular link ( firestore ). The images are completely downloaded from the server and visible on each cell of collectionview as usual. But the problem is that when…
Visal Sambo
  • 1,270
  • 1
  • 19
  • 33
1
vote
0 answers

NSCache in Swift : does not save to disk

I don't know what I am missing here to cache object. But no object is ever cached in the disk import UIKit class MyObject { var title:String? var desc:String? init(title: String, desc: String) { self.title = title …
user4422315
1
vote
0 answers

Table view with images stutters while scrolling

I have a table view which loads custom table view cells. In the table view cell I have an image view, among other controls. The problem is that the table view stutters while scrolling, even though the images are being read from Cache or documents…
StudentX
  • 2,506
  • 5
  • 19
  • 28
1
vote
0 answers

NSData in NSCache swift 3.0

How can I save Data in NSCache in Swift 3.0? lazy var cache = NSCache() When I try creating such array, I get the error: "Type 'Data' doesn't conform to 'AnyObject'" In Swift 2.0, the following code worked: lazy var cache…
1
vote
1 answer

Fast Caching.. iOS FBApi

I am fetching from the fbgraph api and showing in a view. the code for fetching is below. func fetchProfile(){ let parameters = ["fields":"email, name, picture.type(large)"] FBSDKGraphRequest(graphPath: "me", parameters:…
Aryan Kashyap
  • 121
  • 1
  • 12
1
vote
1 answer

iOS Core Data dispatch_async background queuing crash

I'm getting a non-reproduceable crash and I'm not sure why. I'm caching images on a background queue. The image names are properties on a Core Data NSManagedObject subclass, CCCard. At the same time, I have a collection view that is also accessing…
abc123
  • 8,043
  • 7
  • 49
  • 80
1
vote
1 answer

Writing an NSCache to disk with NSKeyedArchiver

I need a dictionary to hold a limited number of objects that need to be created with an internet connection and cache them so they remain available when there's no internet connection. NSCache seems ideal since I can specify a limit or it will…
Cbas
  • 6,003
  • 11
  • 56
  • 87
1
vote
2 answers

How to Implement Time-based NSCache with setObject Swift 2.0

I have an NSDictionary which I cached. I need to implement a time-based setObject with timestamp. NSCache Class doesn't have a setExpiry. Any help would be appreciated. This is the extension I have so far: import Foundation extension NSCache…
Tal Zion
  • 6,308
  • 3
  • 50
  • 73