-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
opts.cache
and share cache between all core sessions (#18)
* Add `opts.cache` and share cache between all core sessions * Trigger Actions * Allow overriding session cache * Pass cache opt to namespaces Co-authored-by: Andrew Osheroff <andrewosh@gmail.com>
- Loading branch information
Showing
5 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
sandbox | ||
coverage | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const test = require('brittle') | ||
const RAM = require('random-access-memory') | ||
|
||
const Corestore = require('..') | ||
|
||
test('core cache', async function (t) { | ||
const store = new Corestore(RAM, { cache: true }) | ||
|
||
const core = store.get({ name: 'core' }) | ||
await core.append(['a', 'b', 'c']) | ||
|
||
const p = core.get(0) | ||
const q = core.get(0) | ||
|
||
t.is(await p, await q) | ||
}) | ||
|
||
test('clear cache on truncate', async function (t) { | ||
const store = new Corestore(RAM, { cache: true }) | ||
|
||
const core = store.get({ name: 'core' }) | ||
await core.append(['a', 'b', 'c']) | ||
|
||
const p = core.get(0) | ||
|
||
await core.truncate(0) | ||
await core.append('d') | ||
|
||
const q = core.get(0) | ||
|
||
t.alike(await p, Buffer.from('a')) | ||
t.alike(await q, Buffer.from('d')) | ||
}) | ||
|
||
test('core cache on namespace', async function (t) { | ||
const store = new Corestore(RAM, { cache: true }) | ||
const ns1 = store.namespace('test-namespace-1') | ||
|
||
const c1 = store.get({ name: 'test-core' }) | ||
const c2 = ns1.get({ name: 'test-core' }) | ||
|
||
await Promise.all([c1.ready(), c2.ready()]) | ||
|
||
t.ok(c1.cache) | ||
t.ok(c2.cache) | ||
}) |