APIIn-memory store

In-memory store

A store that keeps small amount of objects and accounts in memory. It is often used as a temporary store before objects are copied onto a permanent store.

Instance creation

InMemoryStore inMemoryStore = InMemoryStore.create();
var inMemoryStore = cn.createInMemoryStore();
my $inMemoryStore = CN::InMemoryStore->create;

Create a new in-memory store. The ID is set to "inMemoryStore:" followed by a random sequence.

InMemoryStore inMemoryStore = new InMemoryStore(id);
var inMemoryStore = new cn.InMemoryStore(id);
my $inMemoryStore = CN::InMemoryStore->new($id);

Instantiates an in-memory store with a specific ID.

Store behavior

The store maintains a list of accounts, and list of objects in memory. All store request are handled through these lists.

Synchronous store access

Objects and accounts can be accessed synchronously. The interface is slightly different from the standard store interface.

CondensationObject object = inMemoryStore.get(hash);
var object = inMemoryStore.get(hash);
my $object = $inMemoryStore->get($hash);

Retrieves an object. If the object does not exist, nullundef is returned.

boolean booked = inMemoryStore.book(hash);
var booked = inMemoryStore.book(hash);
my $booked = $inMemoryStore->book($hash);

Books an object, and returns whether the object exists on the store.

inMemoryStore.put(hash, object);
inMemoryStore.put(hash, object);
$inMemoryStore->put($hash, $object);

Adds an object to the store.

ArrayList<Hash> hashes = inMemoryStore.list(accountHash, boxLabel);
var hashes = inMemoryStore.list(accountHash, boxLabel);
var $hashes = $inMemoryStore->list($accountHash, $boxLabel);

Lists a box. Unless an invalid box label is provided, the operation always succeeds.

boolean success = inMemoryStore.add(accountHash, boxLabel, hash);
var success = inMemoryStore.add(accountHash, boxLabel, hash);
my $success = $inMemoryStore->add($accountHash, $boxLabel, $hash);

Adds a hash to a box. The operation always succeeds unless an invalid box label is provided.

inMemoryStore.remove(accountHash, boxLabel, hash);
inMemoryStore.remove(accountHash, boxLabel, hash);
$inMemoryStore->remove($accountHash, $boxLabel, $hash);

Removes a hash from a box.

Garbage collection

inMemoryStore.collectGarbage(System.currentTimeMillis() - 3600 * 1000);
inMemoryStore.collectGarbage(new Date().getTime() - 3600 * 1000);
$inMemoryStore->collectGarbage((time() - 3600) * 1000);

Removes unused objects and empty accounts. All objects reachable from a box, as well as all objects that have been put or booked after the given limit time are kept in the store, while other objects are removed. Empty accounts are removed as well.

Note that this runs synchronously on the calling thread.