This project contains a simple app with some examples of possible ways to build a concurrent and thread safe resource cache (caching of remotely fetched resources).
Profile the example app with the Instruments tool using the Swift Concurrency profiling template, and see how the different resource cache implementations behave in terms of Task creation etc.
The code is heavily inspired by these WWDC videos (which I really recommend watching!):
- Eliminate data races using Swift Concurrency.
- Swift concurrency: Behind the scenes.
- Beyond the basics of structured concurrency.
- Visualize and optimize Swift concurrency.
This project also contain some example utility classes for safely managing protected values across Threads / concurrency contexts:
- AtomicCount: A Thread safe counter value using Swift Atomics.
- LockedCount: A Thread safe counter value using NSLock.
- WaitingContinuationsLocker: Thread safe storage for Continuations of a particular type (waiting to be resumed).
Some Unit Tests are included to help show the differences between the different implementations of a resource cache, but due to the nature of concurrency they are most reliable when ran individually.