Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Get data always hits the network without persister #364

@mapacheverdugo

Description

@mapacheverdugo

First of all, I'm still using Java and I'm really noob with RxJava.

I'm trying to retrieve data from a localhosted API, but when I call get() it always hits the network, even when I've previously called the method.

I've been trying many examples, but the problem persists and I don't know what I'm doing wrong. If you could give me an example of the simplest way to make it work, I would appreciate it very much. Here is my current code:

Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
                .create();

ApiUtem apiUtem = new Retrofit.Builder()
                .baseUrl(ApiUtem.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                .create(ApiUtem.class);

Store<Student, BarCode> store = StoreBuilder.<Student>barcode()
                .fetcher(barCode -> apiUtem.getStudent(barCode.getKey(), mToken)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()))
                .memoryPolicy(
                        MemoryPolicy
                                .builder()
                                .setExpireAfterWrite(10)
                                .setExpireAfterTimeUnit(TimeUnit.MINUTES)
                                .build()
                )
                .open();
BarCode barcode = new BarCode(Student.class.getSimpleName(), "19649846");
store.getWithResult(barcode)
                    .subscribe(studentResult -> {
                        if (studentResult.isFromCache()) {
                            Log.d(TAG, "Cache");
                        } else {
                            Log.d(TAG, "Network");
                        }
                    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions