Skip to content

Commit

Permalink
add new method sync()
Browse files Browse the repository at this point in the history
  • Loading branch information
sumimakito committed Feb 27, 2015
1 parent f47125f commit 7d34df1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ pkvdb.remove(k); //k must be type of String/Integer/Long/Double/Float/Boolean/JS
pkvdb.persist();
```

* Sync 同步

*For multi-instance purpose, but we don't recommend you to do so. Frequently synchronization will affect the performance. 为多实例目的而设计,但不推荐使用。频繁地同步操作将会影响性能。*

> This method will synchronize current database from persisted version(Database dbName must be the same or both are default).
> 这个方法将会使数据从已持久化版本同步至当前数据库,并覆盖当前内容(数据库名称必须相同或均为默认)。
```java
PersistableKeyValueDatabase pkvdb1 = new QuickKV(this).getDefaultPersistableKVDB();
PersistableKeyValueDatabase pkvdb2 = new QuickKV(this).getDefaultPersistableKVDB();
pkvdb1.put("key", "value");
pkvdb1.persist();
pkvdb2.sync();
String value = pkvdb2.get("key").toString();
System.out.println(value);
//Output: "value"
```

* Clear 清除数据

> This method will clear all data in the specified database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void setPersistInterval(int interval)
Log.w(QKVConfig.PUBLIC_LTAG, "Failed to set persist interval: Interval cannot less than 0!");
}
}

public void sync(){
this.loadPKVDB();
Log.i(QKVConfig.PUBLIC_LTAG, "Persistable database synchronized!");
}

@Override
public void put(Object k, Object v)
Expand Down Expand Up @@ -111,6 +116,7 @@ private void loadPKVDB()
{
try
{
this.dMap.clear();
FileInputStream kvdbFis = pContext.openFileInput(dbName == null ?QKVConfig.PKVDB_FILENAME: dbName);
byte[] bytes = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down

0 comments on commit 7d34df1

Please sign in to comment.