refactor: use contextlib.suppress and sort __slots__ in backends
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from typing import Any
|
||||
@@ -13,7 +14,7 @@ from fastapi_traffic.backends.base import Backend
|
||||
class MemoryBackend(Backend):
|
||||
"""Thread-safe in-memory backend with LRU eviction and TTL support."""
|
||||
|
||||
__slots__ = ("_data", "_lock", "_max_size", "_cleanup_interval", "_cleanup_task")
|
||||
__slots__ = ("_cleanup_interval", "_cleanup_task", "_data", "_lock", "_max_size")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -127,10 +128,8 @@ class MemoryBackend(Backend):
|
||||
"""Stop cleanup task and clear data."""
|
||||
if self._cleanup_task is not None:
|
||||
self._cleanup_task.cancel()
|
||||
try:
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
await self._cleanup_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
self._cleanup_task = None
|
||||
await self.clear()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user