Skip to content

Commit 726ff55

Browse files
author
alafighting
committed
增加使用说明
1 parent 156ffe7 commit 726ff55

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
## 咔咔缓存(KakaCache)
22
> 咔咔一声,缓存搞定。这是一个专用于解决Android中网络请求及图片加载的缓存处理框架
33
4+
## 如何使用
5+
6+
### 准备Retrofit
7+
```java
8+
retrofit = new Retrofit.Builder()
9+
.baseUrl("https://api.github.com/")
10+
.addConverterFactory(KakaCache.gsonConverter())
11+
.addCallAdapterFactory(KakaCache.rxCallAdapter())
12+
.build();
13+
```
14+
15+
### 定义接口
16+
```java
17+
@GET("users/{user}/repos")
18+
@CACHE(value = "custom_key_listRepos", strategy = CacheAndRemoteStrategy.class)
19+
rx.Observable<ResultData<List<GithubRepoEntity>>> listReposForKaka(@Path("user") String user);
20+
```
21+
22+
### 调用接口
23+
```java
24+
service.listReposForKaka("alafighting")
25+
.subscribeOn(Schedulers.io())
26+
.observeOn(AndroidSchedulers.mainThread())
27+
.subscribe(data -> {
28+
LogUtils.log("listReposForKaka => "+data);
29+
}, error -> {
30+
LogUtils.log(error);
31+
});
32+
```
33+
34+
### or 太麻烦?你要的一步到位!!
35+
再原有代码的基础上,仅需一行代码搞定
36+
```java
37+
.compose(KakaCache.transformer(KEY_CACHE, new FirstCacheStrategy()))
38+
```
39+
40+
在这里声明缓存策略即可,不影响原有代码结构
41+
42+
443
## 支持特性
544

645
#### 缓存层级 - 更优良可靠的缓存

0 commit comments

Comments
 (0)