Skip to content

Commit c40189a

Browse files
CopilotBorda
andcommitted
Align S3 backend with metrics framework
- Add metrics parameter to _S3Core.__init__() - Pass metrics to S3 core in cachier decorator - Add metrics import to s3.py - Update S3 core docstring to document metrics parameter - Ensures S3 backend supports metrics like all other backends Addresses comment 4010458432: aligns with latest codebase Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
1 parent dad326d commit c40189a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/cachier/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def cachier(
373373
s3_endpoint_url=s3_endpoint_url,
374374
s3_config=s3_config,
375375
entry_size_limit=size_limit_bytes,
376+
metrics=cache_metrics,
376377
)
377378
else:
378379
raise ValueError("specified an invalid core: %s" % backend)

src/cachier/cores/s3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
from ..config import CacheEntry
2121
from .base import RecalculationNeeded, _BaseCore, _get_func_str
2222

23+
try:
24+
from ..metrics import CacheMetrics
25+
except ImportError:
26+
CacheMetrics = None # type: ignore[assignment,misc]
27+
2328
S3_SLEEP_DURATION_IN_SEC = 1
2429

2530

@@ -62,6 +67,8 @@ class _S3Core(_BaseCore):
6267
Optional ``botocore.config.Config`` object passed when creating the client.
6368
entry_size_limit : int, optional
6469
Maximum allowed size in bytes of a cached value.
70+
metrics : CacheMetrics, optional
71+
Metrics collector for tracking cache performance.
6572
6673
"""
6774

@@ -77,6 +84,7 @@ def __init__(
7784
s3_endpoint_url: Optional[str] = None,
7885
s3_config: Optional[Any] = None,
7986
entry_size_limit: Optional[int] = None,
87+
metrics: Optional["CacheMetrics"] = None,
8088
):
8189
if not BOTO3_AVAILABLE:
8290
_safe_warn(
@@ -88,6 +96,7 @@ def __init__(
8896
hash_func=hash_func,
8997
wait_for_calc_timeout=wait_for_calc_timeout,
9098
entry_size_limit=entry_size_limit,
99+
metrics=metrics,
91100
)
92101

93102
if not s3_bucket:

0 commit comments

Comments
 (0)