遇到問題?歡迎訪問GitHub頁面提交Issue https://github.com/SumiMakito/QuickKV ,同時(shí)也歡迎收藏項(xiàng)目
這個(gè)方法將會(huì)使數(shù)據(jù)從已持久化版本同步至當(dāng)前數(shù)據(jù)庫。
0.8.1版本后引入異步支持
合并模式默認(rèn)開啟
合并模式(true):將已持久化的部分覆蓋至當(dāng)前數(shù)據(jù)庫,其他數(shù)據(jù)保持原樣。
非合并模式(false):先清除數(shù)據(jù)庫內(nèi)容,再將已持久化的數(shù)據(jù)載入至當(dāng)前數(shù)據(jù)庫。小心數(shù)據(jù)丟失
qkvdb1.put("key", "value"); qkvdb1.persist(); qkvdb2.get("key"); //Output: null (Key doesn't exist) qkvdb2.get("qkv2"); //Output: "another_value" (qkvdb1 doesn't have this key-value) qkvdb2.sync(true); //Merge mode is true qkvdb2.get("key").toString(); //Output: "value" qkvdb2.get("qkv2"); //Output: "another_value" qkvdb2.sync(false); //Merge mode is false qkvdb2.get("qkv2"); //Output: null (because qkvdb doesn't have this key-value) //Async (0.8.1+) qkvdb2.sync(new KeyValueDatabase.Callback(){ @Override public void onSuccess(){ //Do something... } @Override public void onFailed(){ //Do something... } }); //Specify a mode for sync with callback qkvdb2.sync(true, new KeyValueDatabase.Callback(){ @Override public void onSuccess(){ //Do something... } @Override public void onFailed(){ //Do something... } });
成功調(diào)用此方法后,數(shù)據(jù)庫會(huì)自動(dòng)持久化一次以應(yīng)用加密/解密。
不需要在持久化前人工解密,一切都將自動(dòng)進(jìn)行。
//You can find the first method in the "Get database" section. //Here is the second method qkvdb.enableEncryption("mykey123"); //"" or null as a key is not allowed!
qkvdb.disableEncryption();
這個(gè)方法將清除指定數(shù)據(jù)庫中所有的數(shù)據(jù)。
qkvdb.clear();
qkvdb.clear(); //Clear it qkvdb.persist(); //Then persist it
這個(gè)方法將從內(nèi)存中釋放非默認(rèn)數(shù)據(jù)庫。
所有未保存的數(shù)據(jù)都將丟失
qucikKv.releaseDatabase("a_database"); qucikKv.releaseAllDatabases(); //One-click-destroy :P
這個(gè)方法將返回一個(gè)布爾值。
qucikKv.isDatabaseOpened("dbAlias");
更多建議: