VictorAlbertos / ReactiveCache

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

Evict/evictAll doesn't seem to be working #4

Closed sahityaPasnoor closed 8 years ago

sahityaPasnoor commented 8 years ago

Hi @VictorAlbertos , evict/evictAll is not working for me.Any idea why?

VictorAlbertos commented 8 years ago

Hi :)

If you want me to help you, you are going to need to copy the code related with the creation of RxCache instance, the provider instance and the way that you are using it.

sahityaPasnoor commented 8 years ago

Instantiation of RxCache

 @Singleton
  @Provides
    ReactiveCache provideReactiveCache() {
        return new ReactiveCache.Builder().diskCacheSize(200).using(context.getCacheDir(), new GsonSpeaker());

    }

Provider Instance

activeProvider = this.reactiveCache.<UserLoginData>provider().lifeCache(60, TimeUnit.MINUTES).withKey("activeProviderData");

Insertion userLoginDataObservable.compose(activeProvider.readWithLoader())

Eviction activeProvider.evict();

VictorAlbertos commented 8 years ago

evict returns an Observable. So, you need to subscribe it.

activeProvider.evict()
         .subscribe();
sahityaPasnoor commented 8 years ago

Nice, works now. i totally missed it. Thanks

PaulWoitaschek commented 8 years ago

What about adding @CheckResult from the support annotations?

VictorAlbertos commented 8 years ago

@PaulWoitaschek I don't follow you.

What annotations are you referring to? The set of annotations from RxCache? And what kind of functionality @CheckResult should add?

PaulWoitaschek commented 8 years ago

Check result is useful at places where the caller things calling a method resulted in a desired action like here.

You would apply the annotation to evict all and the ide will show a warning if you just called that method without subscribing. Also see https://developer.android.com/reference/android/support/annotation/CheckResult.html

VictorAlbertos commented 8 years ago

That would be great. But ReactiveCache is a pure java module, so it's not possible to use any Type from the Android SDK.

PaulWoitaschek commented 8 years ago

It's part of the support library and has an own artifact containing only the annotations

VictorAlbertos commented 8 years ago

Extracted from the docs:

If you want to use annotations in a Gradle module that is not using the Android Plugin for Gradle (com.android.application or com.android.library) but is using the Gradle Java plugin instead, you must include the SDK repository explicitly because the Android support libraries are not available from the JCenter Java repository:

repositories {
   jcenter()
   maven { url '<your-SDK-path>/extras/android/m2repository' }
}

So, at least you know a way to detect dynamically the path to SDK, this will broke the build for everyone who wants to compile the library.