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
6
votes
1 answer

NSCache removes all its data when app goes to background State

I am working with NSCache, I am using NSCache to store images. I am showing images on UITableView. Whenever I add images first they are resized and then added to the table and then to NSCache. eveything works fine. But whenever app goes to…
Ranjit
  • 4,566
  • 10
  • 53
  • 118
6
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
  • 257
  • 1
  • 6
  • 11
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
6
votes
2 answers

Best usage of NSCache across an app

I'm wondering if it's best 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
  • 377
  • 1
  • 9
5
votes
2 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
  • 835
  • 12
  • 37
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
5
votes
3 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
  • 43,056
  • 20
  • 131
  • 184
4
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,368
  • 2
  • 19
  • 43
4
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
  • 1,935
  • 17
  • 30
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
  • 1
  • 9
3
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
  • 325
  • 6
  • 19
3
votes
2 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
  • 213
  • 2
  • 14
3
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
3
votes
1 answer

NSCache objectForKey: always return nil after memory warning on iOS 8

I came across a problem that only happened on iOS 8. I used the NSCache to store my images. After receiving memory warning, I would fetch images and store into cache again. However the cache can't store my images anymore after warning. It always…
yuhua
  • 1,179
  • 7
  • 18
3
votes
4 answers

How to Clear PFFIle Cache (Parse.com)

I have an app that downloads and displays a lot of images from parse. An image is added to the database almost every minute. Since PFFile is automatically cached with no expiration date, even though I only need to display recent images, the older…
Subash
  • 972
  • 12
  • 26
1
2
3
9 10