VictorAlbertos / ReactiveCache

A reactive cache for Android and Java which honors the reactive chain.
Apache License 2.0
240 stars 24 forks source link

Do not evict expired data when `useExpiredDataWhenNoLoaderAvailabe` #20

Closed NaSOS closed 4 years ago

NaSOS commented 6 years ago

@VictorAlbertos I know that this has been answered before but I would like you to elaborate a bit on it again.

Although I have enabled the useExpiredDataWhenNoLoaderAvailabe when I launch the app the ProcessorProvidersBehaviour starts the EvictExpiredRecordsPersistence and my expired data are being evicted and thus, I get the RxCacheException: The Loader provided did not return any data and there is not data to load from the Cache error.

I think that this is misleading since I would expect to always have data in my cache (since I have loaded them at least once of course) and just refresh them whenever possible. So I think it would be better to not evict expired records on app launch when useExpiredDataWhenNoLoaderAvailabe.

VictorAlbertos commented 6 years ago

By enabling useExpiredDataWhenNoLoaderAvailabe you're not preventing evicting data if the limit for storing it has been reached. What you're doing is allowing to fallback to expired data when the loader returns no data (an error).

So if you want to achieve that behaviour just configure the limit in megabytes for the data to be persisted.

By default, RxCache sets the limit in 100 megabytes, but you can change this value by calling setMaxMBPersistenceCache method when building the provider instance.

new RxCache.Builder()
            .setMaxMBPersistenceCache(maxMgPersistenceCache) 
NaSOS commented 6 years ago

First of all thanks for the answer. I've already read about the cache size limit but currently I am just caching a couple or requests that sum up to some Kilobytes so this is not the issue here.

Please keep in mind that while using the app and reloading the same data the mechanism works perfect and nothing gets evicted. The issue occurs when I kill and re-launch the app.