adamritter / nostr-relaypool-ts

A Nostr RelayPool implementation in TypeScript using only nostr-tools library as a dependency
https://www.npmjs.com/package/nostr-relaypool
MIT License
63 stars 17 forks source link

Hint for storing data in localStorage #26

Open adamritter opened 1 year ago

adamritter commented 1 year ago

While having a LRU cache is a great idea, the most important queries are running permamently. Events generated by these queries need to be stored in localStorage even if they are not recent.

A simple API is RelayPool::store(evvent), Event::store(), and store(cb: OnEvent) : OnEvent .

localStorage should at least be updated before closing the window, but also probably a few second delay of debounce is probably good.

adamritter commented 1 year ago

Alternative storage is indexedb, maybe 2 entries are enough: 1 for hinted storage, other for LRU (though LRU can store 50MB, doesn't need to be super small, and can load slower, it's not a problem).

adamritter commented 1 year ago

Instead of the store function, a better hint is probably just the author pubkey and followed pubkeys.

This way caching can divide available space between author events, followed events and other events (40%, 40%, 20%???).

Divide the space between authors, and inside it between kinds.

Store freshest events.

This type of caching can be used in multiple stages (local, limited to 4MB, and larger cache that can be 50MB).

adamritter commented 1 year ago

Actually event author pubkey and division / space allocation are enough for these. Also all replies and reply profiles should be stored.