block cache metrics

This commit is contained in:
Jack Robison 2020-12-29 21:40:39 -05:00
parent 8ff813f689
commit ab3d9bd080
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -55,7 +55,7 @@ class Daemon:
self.available_rpcs = {}
self.connector = aiohttp.TCPConnector()
self._block_hash_cache = LRUCache(100000)
self._block_cache = LRUCache(10000)
self._block_cache = LRUCache(2**16, metric_name='block', namespace=NAMESPACE)
async def close(self):
if self.connector:
@ -249,8 +249,10 @@ class Daemon:
async def deserialised_block(self, hex_hash):
"""Return the deserialised block with the given hex hash."""
if not self._block_cache.get(hex_hash):
self._block_cache[hex_hash] = await self._send_single('getblock', (hex_hash, True))
if hex_hash not in self._block_cache:
block = await self._send_single('getblock', (hex_hash, True))
self._block_cache[hex_hash] = block
return block
return self._block_cache[hex_hash]
async def raw_blocks(self, hex_hashes):