Caching with SwiftUI Task Modifier | REST API Data | In Memory & Disk | Expiration Timestamp

preview_player
Показать описание
We are going to learn on how to implement Caching Layer to a News App that currently using iOS 15 SwiftUI Task Modifier to trigger data fetching. At the end of this video, we should be able implement the Cache with these requirements below to improve the efficiency of our app:
- In-memory based Cache.
- Disk based Cache that survives app restart. Display cache data when the user is offline.
- Thread safe data access with Actor type.
- Expiration timestamp cache invalidation
- Manual cache invalidation.
- Automatic cache eviction when system resource are low.

#swiftui #iosdev #caching

This tutorial is made using the following:
- Xcode 13 Beta 5
- iOS 15 Developer Beta 7

Timeline:
00:00 Introduction, Demo, and Getting Started
06:39 Building In Memory Cache Actor
17:49 Integrating Cache to Observable Object/ViewModel
23:20 Testing and Handling Manual Cache Invalidation
29:30 Create Cache Protocol and Shared Extension
36:32 Tracking Keys of Cache Entry
41:32 Building Disk Cache Actor with Codable Support
48:47 Integrating Disk Cache to Observable Object and Testing
53:01 Challenge and Conclusion

GitHub Repository Link:

Part 1 - Build an iOS News App with SwiftUI 3 & NewsAPI | Full Course:

Part 2 - Add iPadOS UX Adaptivity to an iOS News App with SwiftUI 3 | Full Course:

Part 3 - Building macOS News App with SwiftUI 3 & NewsAPI | Full Course:

Part 4 - Building watchOS News App with SwiftUI 3 & NewsAPI | Full Course:

Part 5 - Building tvOS News App with SwiftUI 3 and NewsAPI:

NewsAPI Website:

Caching in Swift | Swift by Sundell:
Рекомендации по теме
Комментарии
Автор

Thanks a lot, very useful for better app performance and less consuming network resources (especially on cellular networks).

rev_kous
Автор

Love your videos, learn a lot from them. You Rock!!!
Thank you for all your hard work

Lvoonok
Автор

I learned a lot here. Thanks for an awesome video!

rickywitherspoon
Автор

Thank you so much for the detailed video, it's a life savior..

md-rubel
Автор

Thank you Alfian... great job. Keep going

Mahadev-xu
Автор

29:02 What happen if the fetching from api failed. The cache already deleted?

shrp
Автор

awesome video and explanation .. thank you so much .. if it's ok I will use your cache protocol in my project ...

muradjam
Автор

At 11:41 interval, will that key which is of type NSString be the same as the key in CacheEntry? Not sure why we need two keys

Kevalkorat
Автор

I am facing an issue in my project which may prevent me from using this cache protocol, my view displays different data types (a dashboard), the view model fetches these data using a function for each data type because each data type comes from a different api, like: getScores, getCounts, getUserInfo, etc ... now I can't define something like: private let cache = InMemoryCache<SomeType>(...) because I need to specialize the cache generic to the type that it fetches, and as the view model fetches many different data types to display them in the "dashboard" view, it's unreasonable to define a cache object for each data type: let scoresCache .. let countsCache ... let userInfoCache .... let ... let ... because this becomes redundant, so my problem is with the generics used in the cache protocol, although it's a nice feature but it has a limitation for cases such mine, any thoughts are highly appreciated.

muradjam
welcome to shbcf.ru