-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinmemory.py
More file actions
28 lines (20 loc) · 848 Bytes
/
Copy pathinmemory.py
File metadata and controls
28 lines (20 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Optional
from cachetools import TTLCache
from github_proxy.cache.backend import CacheBackend
from github_proxy.cache.backend import CacheBackendConfig
from github_proxy.cache.backend import Value
class InMemoryCache(CacheBackend, scheme="inmemory"):
"""Useful for testing purposes"""
def __init__(self, config: CacheBackendConfig):
super().__init__(config)
self._store: TTLCache[str, Value] = TTLCache(
maxsize=1024, ttl=self.config.cache_ttl
)
def _make_key(
self, resource: str, filter_: Optional[str], representation: str
) -> str:
return f"{resource}/{filter_}/{representation}"
def _get(self, key: str) -> Optional[Value]:
return self._store.get(key)
def _set(self, key: str, value: Value) -> None:
self._store[key] = value