How to store data in NSCache in ios?

I am very new to NSCache.

I have an API call that leads to multiple objects. How to store these objects in NSCache so that I do not require an API call again.

How much data can be stored in NSCache. Is there a specific limit for storing data in NSCache.

Please help me.

+6
source share
2 answers

Take a look at the documentation and sample code .

An NSCache object is a collection-like container or cache that stores key-value pairs similar to the NSDictionary class.

Here's a good explanation Nick Zitzmann.

NSCache is similar to NSMutableDictionary, with differences:
1. It is guaranteed that it will be thread safe.
2. Access to it is much slower. 3. It may drop objects from time to time. You can set costs and limits, but they are not guaranteed. 4. This is not a free connection to anything in CoreFoundation.
5. You cannot request the number of objects in the cache.
6. You cannot list the cache.

I can only recommend using NSCache to store objects that you don't care about whether they were arbitrarily destroyed. If objects should not be or if access speed is a problem, then use NSMutableDictionary instead.

+10
source

From the documentation for your relevance

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSCache_Class/Reference/Reference.html

NSCache has many automatic deletion policies that ensure that it does not use too much of system memory. The system automatically enforces these policies if other applications require memory. When invoked, these policies remove some items from the cache, minimizing the amount of memory.

+1
source

Source: https://habr.com/ru/post/927341/


All Articles