1

I am trying to get some clarity on how I can use Akavache for multiple users on the same phone.

I am currently using BlobCache.LocalMachine, and I am getting and setting cached data using GetOrFetchObject( key ) and InsertObject( key ). What I am noticing is that the key here is just a generic identifier that I am giving to the data, hence regardless of who logs into my app, the data is getting refreshed based on the same key, not proprietary to that user.

Reza
  • 5,314
  • 5
  • 21
  • 35
  • Looking at the github repo, any data associated with a user is manipulated via statements like `BlobCache.UserAccount.InsertObject` and `...GetObject`. See example code at https://github.com/reactiveui/Akavache, or in README.md. – ToolmakerSteve Oct 26 '21 at 03:35
  • @ToolmakerSteve Thanks! By googling the terms you mentioned, I found this https://github.com/reactiveui/Akavache/issues/271 What's unclear to me is that the data I am caching consists of text and images, the Akavache home page says that UserAccount should be used for user settings only. https://github.com/reactiveui/Akavache – Reza Oct 26 '21 at 03:39
  • Still trying to crack my head around this, I assumed it would be as easy as just executing InvalidateAll() on logout, but that doesn't seem to work. Then I tried prefixing the cache key with the the userId, but that doesn't work either. :-( – Reza Oct 30 '21 at 03:22
  • OK, reading those, I misunderstood when to use UserAccount. You should just use LocalMachine. **Update your question to show** your exact code for "prefixing the cache key with the userId". Print out the string key you ended up with. For user #1234, something like `"1234_keyname"`? And show what goes wrong. That should work; its just a longer string. – ToolmakerSteve Nov 03 '21 at 00:02
  • 1
    I found the culprit, user error! In my actual service that fetches data I was setting the userId in the constructor, so it worked when the app was started, but during a logout, the userId wasn't getting updated. I am now checking for the userId when I do CRUD and voila it works. – Reza Nov 06 '21 at 01:33

0 Answers0