简体   繁体   English

iOS 使用realm做缓存效率高吗?

[英]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.重构项目,我使用 realm 进行缓存。 Implementation realm by caching, I cache the data of the next view controller. But realm operate in Main Thread.通过缓存实现realm,我缓存下一个view controller的数据。但是realm在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.每次我进入下一个视图 controller,Main Thread 都处于活动状态。(读,写.. CRUD)我想知道这是一种有效的方式还是资源密集型操作。 Is using Realm for caching a good practice?使用 Realm 进行缓存是一种好习惯吗?

Local FileManager Caching -> Realm Caching本地 FileManager 缓存 -> Realm 缓存

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. Realm 默认在主线程上运行,如果同时发生大量读写操作,这可能会成为问题,因为这会导致主线程阻塞并导致糟糕的用户体验。 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.不过Realm也支持后台线程,可以让你在后台线程上进行读写操作,这样就可以保持主线程的响应。 Using a background thread to perform operations on Realm can be a good solution to overcome this performance bottleneck and improve the user experience.使用后台线程对Realm进行操作,可以很好的解决这个性能瓶颈,提升用户体验。 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 可以处理大量数据,但如果您的缓存非常大,使用不同的解决方案可能更有效,例如基于文件的缓存。

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. Realm 的缓存机制是内置的,与基于文件的存储不同,它可以更有效地处理具有高读写比的数据,您必须手动处理缓存机制。Realm 可以很好地解决 iOS 中的数据缓存问题,但了解使用它的限制和权衡很重要,尤其是在性能和数据大小方面。我建议您分析您的应用程序并衡量不同解决方案的性能,然后选择最适合您需求的解决方案。

Hope it helps and let me know if you have any other questions.希望对您有所帮助,如果您有任何其他问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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