TwineCache

@twine-protocol/twine-core v0.1.0Docs


twine-js / @twine-protocol/twine-core / TwineCache

Class: TwineCache

A store that caches twines in memory

Extends

Constructors

new TwineCache()

new TwineCache(maxSize): TwineCache

Create a new twine cache

Parameters

Parameter
Type
Default value
Description

maxSize

number

10000

The maximum number of twines to keep in memory (default 10000)

Returns

TwineCache

Overrides

MemoryStore.constructor

Defined in

packages/twine-core/src/store/memory-store.ts:287

Properties

Property
Modifier
Type
Description
Inherited from
Defined in

chainStore

protected

Map<string, Chain>

Chains are stored in a map with the CID as the key

MemoryStore.chainStore

chainStorageMeta

protected

Map<string, ChainStorageMeta>

Chain storage metadata

MemoryStore.chainStorageMeta

pulseStore

protected

CacheMap<string, Pulse>

Pulses are stored in a map with the CID as the key

MemoryStore.pulseStore

maxSize

protected

number

The maximum number of twines to keep in memory

MemoryStore.maxSize

Methods

get()

get(cid): null | Chain | Pulse

Parameters

Parameter
Type

Returns

null | Chain | Pulse

Deprecated

Defined in

packages/twine-core/src/store/memory-store.ts:294


add()

add(twine): void

Parameters

Parameter
Type

twine

Twine<any>

Returns

void

Deprecated

Defined in

packages/twine-core/src/store/memory-store.ts:303


setMaxSize()

setMaxSize(maxSize): void

Set the maximum number of twines to keep in memory

If the store is already larger than the new max size, the oldest twines will be removed.

Parameters

Parameter
Type

maxSize

number

Returns

void

Inherited from

MemoryStore.setMaxSize

Defined in

packages/twine-core/src/store/memory-store.ts:70


fetch()

fetch(cid): null | Chain | Pulse

Fetch a twine from storage, returning null if it is not found

it is NOT expected that the twine signature is checked, that is for the Resolver to do.

Parameters

Parameter
Type
Description

cid

The CID of the twine to fetch

Returns

null | Chain | Pulse

Inherited from

MemoryStore.fetch

Defined in

packages/twine-core/src/store/memory-store.ts:81


has()

has(cid): boolean

Check if a cid can be resolved

Parameters

Parameter
Type
Description

cid

The CID to check

Returns

boolean

True if the CID can be resolved, false otherwise

Inherited from

MemoryStore.has

Defined in

packages/twine-core/src/store/memory-store.ts:97


delete()

delete(cid): void

Delete a twine from storage

Parameters

Parameter
Type
Description

cid

The CID of the twine to delete

Returns

void

Inherited from

MemoryStore.delete

Defined in

packages/twine-core/src/store/memory-store.ts:105


save()

save(twine): void

Save a twine to storage

Parameters

Parameter
Type
Description

twine

Twine<any>

The twine to save

Returns

void

Inherited from

MemoryStore.save

Defined in

packages/twine-core/src/store/memory-store.ts:147


saveMany()

Save many twines to storage

saveMany(twines)

saveMany(twines): Promise<void>

Save many twines to storage

Parameters

Parameter
Type
Description

twines

AsyncIterable<Twine<TwineValue>, any, any>

The twines to save

Returns

Promise<void>

Inherited from

MemoryStore.saveMany

Defined in

packages/twine-core/src/store/memory-store.ts:159

saveMany(twines)

saveMany(twines): void

Save many twines to storage

Parameters

Parameter
Type

twines

Iterable<Twine<TwineValue>, any, any>

Returns

void

Inherited from

MemoryStore.saveMany

Defined in

packages/twine-core/src/store/memory-store.ts:160


chains()

chains(): MapIterator<Chain>

Get an iterator of all the chains in the store

Returns

MapIterator<Chain>

Inherited from

MemoryStore.chains

Defined in

packages/twine-core/src/store/memory-store.ts:181


pulses()

pulses(chainCid, start?, options?): AsyncGenerator<Pulse, any, any>

Get an async iterator of all the pulses in a chain

Parameters

Parameter
Type

chainCid

start?

number | IntoCid

Returns

AsyncGenerator<Pulse, any, any>

Inherited from

MemoryStore.pulses

Defined in

packages/twine-core/src/store/memory-store.ts:188


resolve()

Resolve a chain from a query

This is the main way to get a pulse or chain from somewhere and have it automatically verified.

If the input is already a successful resolution, it will be returned as is.

If the input is a chain or pulse, it will be resolved as a chain or pulse resolution.

resolve(query, options)

resolve(query, options?): Promise<ChainResolution>

Resolve a chain from a query

This is the main way to get a pulse or chain from somewhere and have it automatically verified.

If the input is already a successful resolution, it will be returned as is.

If the input is a chain or pulse, it will be resolved as a chain or pulse resolution.

Parameters

Parameter
Type
Description

query

The query to resolve

options?

Options for the resolution

Returns

Promise<ChainResolution>

A chain or pulse resolution

A chain or pulse resolution

Examples

const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
if (chain) {
  console.log('chain', chain)
} else {
  console.log('no chain')
}
const { chain, pulse } = await resolver.resolve({
  chain: 'bafybeib3...',
  pulse: 'bafybeib3...'
})

if (pulse) {
  console.log('pulse', pulse)
} else {
  console.log('no pulse')
}

Inherited from

MemoryStore.resolve

Defined in

packages/twine-core/src/store/memory-store.ts:215

resolve(query, options)

resolve(query, options?): Promise<PulseResolution>

Resolve a pulse (with its chain) from a query

Parameters

Parameter
Type

Returns

Promise<PulseResolution>

A chain or pulse resolution

Inherited from

MemoryStore.resolve

Defined in

packages/twine-core/src/store/memory-store.ts:216


resolveLatest()

resolveLatest(chainCid, options?): Promise<PulseResolution>

Resolve the latest pulse of a chain

Parameters

Parameter
Type
Description

chainCid

The chain CID or chain itself to resolve the latest pulse from

options?

Options for the resolution

Returns

Promise<PulseResolution>

A pulse resolution

Inherited from

MemoryStore.resolveLatest

Defined in

packages/twine-core/src/store/memory-store.ts:230


resolveIndex()

resolveIndex(chain, index, options?): Promise<PulseResolution>

Resolve a pulse by index

Parameters

Parameter
Type
Description

chain

The chain CID or chain itself to resolve the pulse from

index

number

The index of the pulse to resolve

options?

Options for the resolution

Returns

Promise<PulseResolution>

A pulse resolution

Inherited from

MemoryStore.resolveIndex

Defined in

packages/twine-core/src/store/memory-store.ts:246

Last updated