mergesort / Boutique

✨ A magical persistence library (and so much more) for state-driven iOS and Mac apps ✨
https://build.ms/boutique/docs
MIT License
899 stars 43 forks source link

Implementing an additional caching layer for StoredValue #62

Closed mergesort closed 2 months ago

mergesort commented 2 months ago

StoredValue saves values to UserDefaults which has it's own layer of caching, but that caching is reserved for primitives such as Bool or String. Since a StoredValue is persisted as data every time they are accessed they have to be decoded using a JSONDecoder, which means every access of a value requires JSON decoding.

That is not very performant, so this pull request introduces an additional in-memory store of a StoredValue, similar to how Store has an in-memory layer to access and use values for the sake of performance. This same logic could be applied to SecurelyStoredValue but is intentionally eschewed to prevent keeping sensitive values in memory, defeating the purpose of SecurelyStoredValue using the system keychain as a backing store.