| Server IP : 66.29.153.156 / Your IP : 216.73.216.223 Web Server : LiteSpeed System : Linux premium322.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64 User : lastyfjz ( 1521) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /././opt/hc_python/lib/python3.12/site-packages/sentry_sdk/ |
Upload File : |
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
_SENTINEL = object()
class LRUCache:
def __init__(self, max_size: int) -> None:
if max_size <= 0:
raise AssertionError(f"invalid max_size: {max_size}")
self.max_size = max_size
self._data: "dict[Any, Any]" = {}
self.hits = self.misses = 0
self.full = False
def set(self, key: "Any", value: "Any") -> None:
current = self._data.pop(key, _SENTINEL)
if current is not _SENTINEL:
self._data[key] = value
elif self.full:
self._data.pop(next(iter(self._data)))
self._data[key] = value
else:
self._data[key] = value
self.full = len(self._data) >= self.max_size
def get(self, key: "Any", default: "Any" = None) -> "Any":
try:
ret = self._data.pop(key)
except KeyError:
self.misses += 1
ret = default
else:
self.hits += 1
self._data[key] = ret
return ret
def get_all(self) -> "list[tuple[Any, Any]]":
return list(self._data.items())