On the lightweight data cache framework rxcache for Android

Requesting network data is the most frequently used function in Android development. The experience of network request determines the user's feeling about the whole app. Therefore, it is very important to use cache reasonably to process the data requested by the network. Reasonable caching and network requests can bring a better experience to the app. Picasso, glass, fresco and other famous frameworks for image caching are very mature and widely used. What programmers should do is to use wheels instead of making wheels repeatedly. However, the caching of network data is mostly self-use and self encapsulation, and everyone needs to carry out cumbersome coding work. Rxcache encapsulates the network cache and adopts rxjava mode, which can be seamlessly connected with other rxjava codes and is very convenient to use.

Rxcache uses lrucache and disklrucache for secondary caching of network request data. It is mainly adapted to the data returned by the interface API, and is not used for caching images, etc. You can set the cache mode, cache size, data expiration time, and provide the function of deleting the cache and emptying all caches according to the key. Gson mode and serialize mode are provided for data storage, conversion and restoration.

Project GitHub address

RxCache

Start using:

First, add dependencies in the gradle of the project:

Rxcache uses jitpack for dependency management, so you need to add the following code in build.gradle of the project first:

Then add the following dependencies in the gradle of the module:

Initialize in your application:

You can also use builder for advanced initialization:

Write cache

Read cache

When reading the cache, there are the following situations:

In case of gson conversion:

Read basic type data, or custom JavaBean data, or array data, and you can get. Class data

The. Class data cannot be obtained by reading list, etc. this method can also be used for the above basic data

In case of serialize mode, the following methods can be used uniformly:

Clear specified cache

Clear all caches

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>