Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/nym-moultest123/memo/v0

Directory · 4 Files
README.md Open

gno.land/p/nym-moultest123/memo/v0

A simple memoization utility to cache function results, backed by a B+ tree (gno.land/p/nt/bptree).

A B+ tree packs many entries per persisted node, so it costs materially less storage and gas per cached entry than an AVL backing would.

 1import "gno.land/p/nym-moultest123/memo/v0"
 2
 3m := memo.New()
 4
 5// Cache expensive computation; subsequent calls with the same key
 6// return the cached result without re-running the function.
 7result := m.Memoize("key", func() any {
 8	return "computed-value"
 9})
10
11m.Invalidate("key") // drop one entry
12m.Clear()           // drop all entries
13m.Size()            // number of cached entries

⚠️ Gno usage: storage updates only persist during transactions. Memoizing during queries/render will not persist and only wastes resources — use this in transaction-driven contexts.

Caveats from the B+ tree backing: it mutates in place (a copy-on-write AVL backing would not), so do not Invalidate/add entries from inside a callback iterating the same Memoizer, and do not copy a non-zero Memoizer by value.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/nym-moultest123/memo/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.