PersistentCacheStore & In Memory Blocking Cache - oppia/oppia-android GitHub Wiki
Table of Contents
PersistentCacheStore
PersistentCacheStore
is the team's replacement to SharedPreferences
except it:
- Never blocks the main thread
- Forces using protocol buffers for the underlying storage structure to encourage background & forward compatibility
- Is a
DataProvider
which means it can be easily interoped with the codebase's otherDataProvider
s
Note as of 8 April 2021: PersistentCacheStore
was created before DataStore
from Android Jetpack was available for production use. The team may eventually migrate to this solution, but it's not currently planned.
In-Memory blocking cache
While not a DataProvider
, InMemoryBlockingCache
is a concurrency primitive the team built to ensure single-threaded access to a single variable in-memory where the cache itself can be safely accessed from multiple threads, and no locking mechanism is needed. This is a coroutine-only utility that is meant to improve cross-thread state sharing performance, and is generally only used in cases where state must be synchronized across multiple threads.
Other cases of background processing
There are other cases of background processing and concurrency that come up on the team, but don't yet have established best practices. One such example is triggering logic from Android's work manager (example: FirebaseLogUploader
). Note that while these approaches aren't fully documented yet, the same best practices & principles above should be observed and enforced to ensure a good experience is provided both to end users and developers maintaining the app.