Skip to content

Commit ffa1ac8

Browse files
authored
Use TTLMap (#60)
* use TTLMap * update
1 parent 051409d commit ffa1ac8

File tree

3 files changed

+264
-304
lines changed

3 files changed

+264
-304
lines changed

dnstapir/key_cache.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import logging
22
import time
33
from abc import abstractmethod
4+
from datetime import timedelta
45

56
import redis
6-
from faas_cache_dict import FaaSCacheDict
77
from opentelemetry import trace
88
from pydantic import BaseModel, Field
9+
from ttlru_map import TTLMap
910

1011
tracer = trace.get_tracer("dnstapir.tracer")
1112

@@ -57,7 +58,7 @@ def set(self, key: str, value: bytes) -> None:
5758
class MemoryKeyCache(KeyCache):
5859
def __init__(self, size: int, ttl: int):
5960
super().__init__()
60-
self.cache = FaaSCacheDict(default_ttl=ttl, max_items=size)
61+
self.cache = TTLMap(ttl=timedelta(seconds=ttl), max_size=size)
6162
self.logger.info("Configured memory key cache size=%d ttl=%d", size, ttl)
6263

6364
def get(self, key: str) -> bytes | None:

0 commit comments

Comments
 (0)