简体   繁体   中英

iOS Is it efficient to use realm for cache?

Now my project is implemented as local file storage. refactoring project, i Using realm to Caching. Implementation realm by caching, I cache the data of the next view controller. But realm operate in Main Thread. Every time I enter the next view controller, Main Thread is active.(read, write.. CRUD) I wonder if it's an efficient way or not a resource-intensive operation. Is using Realm for caching a good practice?

Local FileManager Caching -> Realm Caching

Realm operates on the main thread by default, which can be a problem if you have a lot of read and write operations happening simultaneously, as this can cause the main thread to become blocked and lead to a poor user experience. However, Realm also supports background threads, which allows you to perform read and write operations on a background thread, so you can keep the main thread responsive. Using a background thread to perform operations on Realm can be a good solution to overcome this performance bottleneck and improve the user experience. Another important factor to consider is the size of the data you need to cache. Realm can handle large amounts of data, but if your cache is extremely large, it might be more efficient to use a different solution, such as a file-based cache.

Realm's caching mechanism is built-in and it makes it more efficient for data that has a high read-write ratio unlike with file-based storage you have to handle the caching mechanism manually.Realm can be a great solution for caching data in iOS, but it's important to understand the limitations and trade-offs of using it, especially in terms of performance and data size.I suggest you to profile your app and measure the performance of the different solutions and choose the one that best fits your needs.

Hope it helps and let me know if you have any other questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM