hyperledger / firefly

Hyperledger FireFly is the first open source Supernode: a complete stack for enterprises to build and scale secure Web3 applications. The FireFly API for digital assets, data flows, and blockchain transactions makes it radically faster to build production-ready apps on popular chains and protocols.
https://hyperledger.github.io/firefly
Apache License 2.0
508 stars 209 forks source link

Centralized cache manager #943

Open awrichar opened 2 years ago

awrichar commented 2 years ago

FireFly has lots of isolated usage of ccache in many different managers. See here and here for examples.

It would make sense to consolidate this under a new, centralized Cache Manager component. It should be created under internal/cache and should follow the pattern set by other managers, particularly the Metrics Manager. It should be a singleton like Metrics Manager, and should be initialized early by Namespace Manager (the root manager). It can then be passed to all other plugins and managers that require it.

The interface can be quite simple, likely something like Get(category string, key string) and Set(category string, key string).

As part of this, it would also make sense to consolidate the config options under a top-level cache key. The blockchain cache is already following this pattern, but other cache configuration is scattered at various levels throughout the config tree. The old keys should be deprecated in favor of new ones that are grouped together under cache.

awrichar commented 2 years ago

Two items with TODOs that aren't yet cached: https://github.com/hyperledger/firefly/blob/bd63308c8cc855b4859ffc114d4ef6fcdcd7f42e/internal/events/tokens_transferred.go#L72 https://github.com/hyperledger/firefly/blob/bd63308c8cc855b4859ffc114d4ef6fcdcd7f42e/internal/events/tokens_approved.go#L72

Might as well add token pools to the cache after centralizing it.