public class DataStore extends Object implements IDataStore
Handle in-memory and persistent case differently:
In in-memory mode, the "cache" is actually the store, so we never evict anything from it.
In persistent mode, we use a LoadingCache
, where an in-memory map is backed by disk.
In this scheme, the key for each value is also the name of the file where the value is stored.
The key is determined as (prefix + "_" + key).
The cache here serves mostly for easily managed synchronization of in-memory/file.
Some on-disk files will be deleted when their number exceed user specified limit.
If 'opts' either has '--memory=true' or a log-path for storing files is not provided, the store is just an in memory cache.
Created by mdhawan on 7/27/16.
IDataStore.KvRecord<T>
Constructor and Description |
---|
DataStore(Map<String,Object> opts,
Consumer<String> cleanupTask)
Return a new DataStore object.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
delete(Class<T> tclass,
String prefix,
String key) |
<T> void |
delete(IDataStore.KvRecord<T> key)
Deletes the value for a key under a prefix.
|
<T> T |
get(Class<T> tclass,
String prefix,
String key) |
<T> T |
get(IDataStore.KvRecord<T> key)
Retrieves the value for a key under a prefix.
|
<T> T |
get(IDataStore.KvRecord<T> key,
T defaultValue)
Retrieves the value for a key or a default value
|
static int |
getChecksum(byte[] bytes) |
<T> void |
put(Class<T> tclass,
String prefix,
String key,
T value) |
<T> void |
put(IDataStore.KvRecord<T> key,
T value)
Stores a value for a key under a prefix (namespace).
|
public static int getChecksum(byte[] bytes)
public <T> void put(Class<T> tclass, String prefix, String key, T value)
put
in interface IDataStore
public <T> T get(Class<T> tclass, String prefix, String key)
get
in interface IDataStore
public <T> void delete(Class<T> tclass, String prefix, String key)
delete
in interface IDataStore
public <T> void put(IDataStore.KvRecord<T> key, T value)
IDataStore
put
in interface IDataStore
key
- record meta informationvalue
- Immutable value (or a value that won't be changed)public <T> T get(IDataStore.KvRecord<T> key)
IDataStore
get
in interface IDataStore
key
- record meta informationpublic <T> T get(IDataStore.KvRecord<T> key, T defaultValue)
IDataStore
get
in interface IDataStore
key
- key meta infodefaultValue
- a default valuepublic <T> void delete(IDataStore.KvRecord<T> key)
IDataStore
delete
in interface IDataStore
key
- record meta informationCopyright © 2019 CorfuDB. All rights reserved.