Skip to content

Commit

Permalink
1. 修正版本号为空时,缓存处理不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kadbbz committed Apr 28, 2023
1 parent c182f0c commit fd12172
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdk 26
versionCode 4
versionName '1.9.0-release'
versionName '1.9.1-release'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -38,7 +38,7 @@ apply plugin: 'com.google.gms.google-services'
apply plugin: "realm-android"

dependencies {
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-analytics:21.2.2'
implementation 'com.github.getActivity:XXPermissions:16.6'
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class LocalKvProxy extends AbstractProxy {
private static final String VERSION_NA = "N/A";
private static final String VALUE_NA = "DATA_NOT_FOUND";
private static final String KEY_TEMPLATE = "%s|%s";

private static final String VERSION_DEFAULT="default";

static final String LOG_TAG="HAC_LocalKvProxy";

@Override
Expand Down Expand Up @@ -86,14 +89,21 @@ public String retrieve2(String key) {
*/
@JavascriptInterface
public void upsertV(String key, String valueString, String version) {

if(null == version){
version = VERSION_DEFAULT;
}

String finalVersion = version;

Realm.getDefaultInstance().executeTransaction (transactionRealm -> {
LocalKv_Bundle bundle = new LocalKv_Bundle();
bundle.key = String.format(KEY_TEMPLATE, getEntryHost(), key);
bundle.value = valueString;
bundle.version= version;
bundle.version= finalVersion;
transactionRealm.insertOrUpdate(bundle);

Log.v(LOG_TAG,"LocalKV has been upsert with key " + key +" on " + getEntryHost());
Log.v(LOG_TAG,"LocalKV has been upsert with key " + key +" on " + getEntryHost() +" value: "+ valueString);
});
}

Expand All @@ -106,11 +116,18 @@ public void upsertV(String key, String valueString, String version) {
*/
@JavascriptInterface
public void retrieveV(String key, String version, String cell) {

if(null == version){
version = VERSION_DEFAULT;
}

String finalVersion = version;

Realm.getDefaultInstance().executeTransaction (transactionRealm -> {

// 确保按照服务器隔离,在这里拼接出真实存储的Key
String bKey = String.format(KEY_TEMPLATE, getEntryHost(), key);
LocalKv_Bundle bundle= transactionRealm.where(LocalKv_Bundle.class).equalTo("key",bKey).equalTo("version",version).findFirst();
LocalKv_Bundle bundle= transactionRealm.where(LocalKv_Bundle.class).equalTo("key",bKey).equalTo("version",finalVersion).findFirst();

if(bundle !=null){
Log.v(LOG_TAG,"Data from LocalKV has been sent. Key: " + bKey);
Expand All @@ -133,14 +150,20 @@ public String retrieveV2(String key, String version) {

final String[] result = new String[1];

if(null == version){
version = VERSION_DEFAULT;
}

String finalVersion = version;

Realm.getDefaultInstance().executeTransaction (transactionRealm -> {

// 确保按照服务器隔离,在这里拼接出真实存储的Key
String bKey = String.format(KEY_TEMPLATE, getEntryHost(), key);
LocalKv_Bundle bundle= transactionRealm.where(LocalKv_Bundle.class).equalTo("key",bKey).equalTo("version",version).findFirst();
LocalKv_Bundle bundle= transactionRealm.where(LocalKv_Bundle.class).equalTo("key",bKey).equalTo("version",finalVersion).findFirst();

if(bundle !=null){
Log.v(LOG_TAG,"Data from LocalKV has been sent. Key: " + bKey);
Log.v(LOG_TAG,"Data from LocalKV has been sent. Key: " + bKey+" value: "+ bundle.value);
result[0] = bundle.value;
}else{
Log.v(LOG_TAG,"Data not found in LocalKV. Key: " + bKey);
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ buildscript {
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
classpath "io.realm:realm-gradle-plugin:10.11.1"
classpath 'com.google.gms:google-services:4.3.15'
classpath "io.realm:realm-gradle-plugin:10.15.1"
}
}

plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
}

task clean(type: Delete) {
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 30 22:04:54 CST 2022
#Fri Apr 28 12:07:53 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit fd12172

Please sign in to comment.