This PR implements the first step of #33758.
This PR Implement a cache layer. All newly created block templates should be stored along with their respective configuration options. Client requests for block templates will specify the maximum age of the template in seconds; that is, how fresh they want the template to be:
If a template with matching options exists in the cache and the interval has not elapsed, a cached template is returned. If no template exists or the interval has elapsed, a new template is generated, stored in the cache, and returned. After insertion, the oldest template is evicted if the cache exceeds its maximum size. The cache has a configurable maximum size (default: 10). It also subscribes to the validation interface’s BlockConnected notification and clears the cache when a new block is connected or disconnected, preventing stale templates from being served. If test_block_validity is set to true in the block creation options and the cached template found has not yet been validated, it is checked and then returned. This stage will also allow sharing of template metadata built from the mining interface for a fee estimation mechanism that requires building a block template to obtain package fee rates and use them for fee estimation, and vice versa. See the discussion in #33389.