Skip to content

Conversation

harrytmthy
Copy link
Owner

Summary

This PR resolves Issue #54 by realigning apply() behavior with EncryptedSharedPreferences (ESP), ensuring getXxx() calls return the expected values immediately after .apply() is invoked, even before disk writes complete.

This lays the foundation for performance enhancements to be explored in #55.

Implementation Details

  • Moved encrypted entry map (Map<Bytes, ByteArray>) from SafeBoxBlobStore to SafeBox, allowing immediate in-memory updates without waiting for disk writes.
  • getXxx(...), contains(...), and getAll() now access a dedicated in-memory entries map in SafeBox, mirroring ESP behavior.
  • Disk persistence via SafeBoxBlobStore is now fully decoupled from in-memory access, triggered only during commit() or apply().
  • Introduced SafeBoxBlobStore.loadPersistedEntries() to be called once during SafeBox's init to hydrate from disk.
  • apply() no longer blocks getXxx() correctness when using real dispatchers like Dispatchers.IO.
  • Added test case: getString_withRealIoDispatcher_shouldReturnCorrectValue() to verify async correctness under real-world scheduling conditions.

Closes #54

This resolves Issue #54 by shifting the in-memory map of encrypted entries out of SafeBoxBlobStore and into SafeBox, ensuring immediate read/write access even before disk writes complete. This aligns with EncryptedSharedPreferences behavior.
@harrytmthy harrytmthy added this to the 1.1.2 milestone Aug 20, 2025
@harrytmthy harrytmthy self-assigned this Aug 20, 2025
@harrytmthy harrytmthy added the bug Something isn't working label Aug 20, 2025
@harrytmthy harrytmthy merged commit 7d2a296 into main Aug 20, 2025
3 checks passed
@harrytmthy harrytmthy deleted the fix/decouple-entry-map branch August 20, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safebox does not behave as original SharedPreferences
1 participant