This repository was archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcache.js
More file actions
55 lines (37 loc) · 1.23 KB
/
cache.js
File metadata and controls
55 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
})
test('false cache option does not enable caching', async function (t) {
const store = new Corestore(RAM)
const core = store.get({ name: 'core' })
await core.ready()
t.absent(core.cache)
})