Files
notepush/src
William Casarin e3c9e2834e cache: refactor cache structure and reduce allocations
This commit reworks the cache data structures and operations to
significantly cut down on unnecessary allocations and improve overall
cache management logic.

Key changes include:

- Replacing event-specific CacheEntry types with a generic CacheEntry<T>
  that stores values and timestamps.

- Removing the old Arc references in HashMap entries, reducing
  reference-counted pointer overhead.

- Providing helper methods (new(), maybe(), empty(), value()) on
  CacheEntry for more ergonomic and explicit value handling.

- Simplifying the retrieval functions (get_mute_list, get_relay_list,
  get_contact_list) by using a shared helper (get_cache_entry) that
  checks for expiration and removes stale entries automatically.

- Streamlining add_event and related cache insertion methods to insert
  the correct CacheEntry variant depending on the event kind.

- Removing unnecessary methods (e.g., references_pubkey) and simplifying
  extensions in nostr_event_extensions.rs.

- Enhancing code clarity by separating expiration logic from retrieval
  and insertion, making the cache easier to maintain, debug, and extend.

These improvements should reduce runtime memory overhead and increase
code clarity, while maintaining the existing external behavior of the
cache. Future changes will be easier to implement, as the new generic
CacheEntry abstraction and simplified code paths provide a more
maintainable foundation.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-09 13:49:08 +09:00
..
2024-12-09 13:49:08 +09:00