Skip to content

Commit 0bd4b7f

Browse files
author
imkarl
committed
升级工程编译工具;新增仅缓存\仅网络策略
1 parent 559f46c commit 0bd4b7f

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'me.tatarka.retrolambda'
33

44
android {
55
compileSdkVersion 24
6-
buildToolsVersion "24"
6+
buildToolsVersion "24.0.2"
77

88
defaultConfig {
99
applicationId "com.im4j.kakacache.rxjava.test"
@@ -28,7 +28,7 @@ dependencies {
2828
compile fileTree(dir: 'libs', include: ['*.jar'])
2929
compile project(':library')
3030

31-
compile 'com.android.support:appcompat-v7:24.0.0'
31+
compile 'com.android.support:appcompat-v7:24.2.0'
3232
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
3333
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
3434
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.2'
8+
classpath 'com.android.tools.build:gradle:2.1.3'
99
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
1010
}
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Sun Aug 28 19:04:30 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

library/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'me.tatarka.retrolambda'
33

44
android {
55
compileSdkVersion 24
6-
buildToolsVersion "24"
6+
buildToolsVersion "24.0.2"
77

88
defaultConfig {
99
minSdkVersion 11
@@ -26,10 +26,9 @@ android {
2626
dependencies {
2727
compile fileTree(dir: 'libs', include: ['*.jar'])
2828
testCompile 'junit:junit:4.12'
29-
compile 'com.android.support:appcompat-v7:24.0.0'
29+
compile 'com.android.support:appcompat-v7:24.2.0'
3030
compile 'com.google.code.gson:gson:2.7'
3131
compile 'io.reactivex:rxandroid:1.2.1'
32-
compile 'com.squareup.okhttp3:okhttp:3.3.1'
3332
compile 'com.squareup.retrofit2:retrofit:2.1.0'
3433
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
3534
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

library/src/main/java/com/im4j/kakacache/rxjava/core/BasicCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ public final <T> boolean save(String key, T value, int maxAge, CacheTarget targe
102102
* @return
103103
*/
104104
public final boolean containsKey(String key) {
105-
mLock.writeLock().lock();
105+
mLock.readLock().lock();
106106
try {
107107
return doContainsKey(key);
108108
} finally {
109-
mLock.writeLock().unlock();
109+
mLock.readLock().unlock();
110110
}
111111
}
112112

library/src/main/java/com/im4j/kakacache/rxjava/netcache/retrofit/KakaRxCallAdapterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public <R> Observable<?> adapt(Call<R> call) {
108108
LogUtils.debug("fileName="+info.getKey());
109109

110110
if (info.getStrategy() == null) {
111-
info.setStrategy(CacheStrategy.FirstCache);
111+
info.setStrategy(CacheStrategy.OnlyRemote);
112112
}
113113

114114
return callAdapter.doAdaptUnwrap(call)

library/src/main/java/com/im4j/kakacache/rxjava/netcache/strategy/CacheStrategy.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@
1313
* @version alafighting 2016-07
1414
*/
1515
public enum CacheStrategy {
16-
/** 优先缓存 */
17-
FirstCache{
16+
/** 仅缓存 */
17+
OnlyCache{
1818
@Override
1919
public <T> Observable<ResultData<T>> execute(String key, Observable<T> source) {
20-
Observable<ResultData<T>> cache = loadCache(key);
21-
Observable<ResultData<T>> remote = loadRemote(key, source);
22-
return Observable.concat(cache, remote)
23-
.firstOrDefault(null, it -> it.data != null)
24-
.subscribeOn(Schedulers.io());
20+
return loadCache(key);
2521
}
2622
},
23+
/** 仅网络 */
24+
OnlyRemote{
25+
@Override
26+
public <T> Observable<ResultData<T>> execute(String key, Observable<T> source) {
27+
return loadRemote(key, source);
28+
}
29+
},
30+
2731
/** 优先服务器 */
2832
FirstRemote{
2933
@Override

0 commit comments

Comments
 (0)