Akavache
Akavache copied to clipboard
Android: no ability to re-init Akavache on Activity re-start
- On a root view, tap Back button
- Android gets to the Home, the main activity is stopped & destroyed
- OnStop() shuts down Akavache in my case
- Then I use the Android App Stack button and choose my app again
- Android re-creates the main activity
- But Akavache static BlobCache is actually ShutdownBlobCache already and there's no way to re-init Akavache. It's EnsureInitialized() does nothing as all the init logic is in the static constructor
Why not get the initialization lazy and re-enterable via EnsureInitialized()?
Hi, did you find a solution or workaround? I'm running in the same issue....
Actually, not. For now, just need to ask user to explicitly re-start the app (yeap, ugly). Considering to fork and move the initialization from the static ctor to a dedicated method..
I would also appreciate it if Akavache would offer a possibility to shutdown and initialize a BlobCache again. We ran into problems with our tests because some of the tests need a Blobcache with a different EncryptionProvider. Unfortunatelly if the Blobcache is already created, you can not change the EncryptionProvider again. So it would be very practical to dispose the Blobcahe after every testcase and then initialize it again.
I use Flush instead of shutdown just to ensure everything in flight gets pushed and so far haven't seen any issues..
As far as for testing maybe just don't use the static stuff and just instantiate your own?
What's this Global Variable nonsense? Why can't I use $FAVORITE_IOC_LIBRARY
You totally can. Just instantiate SQLitePersistentBlobCache or SQLiteEncryptedBlobCache instead - the static variables are there just to make it easier to get started.
If you set the static properties to something it will just use those instead
So like in my unit tests I have this inside TestCleanup
BlobCache.LocalMachine.InvalidateAll().Wait();
BlobCache.InMemory.InvalidateAll().Wait();
BlobCache.Secure.InvalidateAll().Wait();
And then this inside TestInitialize
BlobCache.InMemory = new InMemoryBlobCache(TestScheduler);
BlobCache.LocalMachine = new InMemoryBlobCache(TestScheduler);
BlobCache.Secure = new InMemoryBlobCache(TestScheduler);
So in your case when the test initializes you could just instantiate a new static property. Or just don't use the static access methods and just create the Blob Cache's yourself
Seems, with the #342 ticket, we have a solution. As recommended, just manage the instancing and flushing of IBlobCache explicitly.
I changed the ShutDown to Flush only and everything is working fine.
@PureWeen @rahamohebbi where do you use flush in your app? Can we use in app.xaml.cs OnSleep and re-initiliza onStart or OnResume?