Skip to content

Commit 6f82691

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f2948b4 commit 6f82691

4 files changed

Lines changed: 129 additions & 83 deletions

File tree

src/cachier/core.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ def _call(*args, max_age: Optional[timedelta] = None, **kwds):
375375
result = _calc_entry(core, key, func, args, kwds, _print)
376376
if cache_metrics:
377377
assert start_time is not None # noqa: S101
378-
cache_metrics.record_latency(time.perf_counter() - start_time)
378+
cache_metrics.record_latency(
379+
time.perf_counter() - start_time
380+
)
379381
return result
380382
if entry is None or (
381383
not entry._completed and not entry._processing
@@ -387,7 +389,9 @@ def _call(*args, max_age: Optional[timedelta] = None, **kwds):
387389
result = _calc_entry(core, key, func, args, kwds, _print)
388390
if cache_metrics:
389391
assert start_time is not None # noqa: S101
390-
cache_metrics.record_latency(time.perf_counter() - start_time)
392+
cache_metrics.record_latency(
393+
time.perf_counter() - start_time
394+
)
391395
return result
392396
_print("Entry found.")
393397
if _allow_none or entry.value is not None:
@@ -411,7 +415,9 @@ def _call(*args, max_age: Optional[timedelta] = None, **kwds):
411415
if cache_metrics:
412416
cache_metrics.record_hit()
413417
assert start_time is not None # noqa: S101
414-
cache_metrics.record_latency(time.perf_counter() - start_time)
418+
cache_metrics.record_latency(
419+
time.perf_counter() - start_time
420+
)
415421
return entry.value
416422
_print("But it is stale... :(")
417423
if cache_metrics:
@@ -460,23 +466,29 @@ def _call(*args, max_age: Optional[timedelta] = None, **kwds):
460466
core.mark_entry_not_calculated(key)
461467
if cache_metrics:
462468
assert start_time is not None # noqa: S101
463-
cache_metrics.record_latency(time.perf_counter() - start_time)
469+
cache_metrics.record_latency(
470+
time.perf_counter() - start_time
471+
)
464472
return entry.value
465473
_print("Calling decorated function and waiting")
466474
if cache_metrics:
467475
cache_metrics.record_recalculation()
468476
result = _calc_entry(core, key, func, args, kwds, _print)
469477
if cache_metrics:
470478
assert start_time is not None # noqa: S101
471-
cache_metrics.record_latency(time.perf_counter() - start_time)
479+
cache_metrics.record_latency(
480+
time.perf_counter() - start_time
481+
)
472482
return result
473483
if entry._processing:
474484
_print("No value but being calculated. Waiting.")
475485
try:
476486
result = core.wait_on_entry_calc(key)
477487
if cache_metrics:
478488
assert start_time is not None # noqa: S101
479-
cache_metrics.record_latency(time.perf_counter() - start_time)
489+
cache_metrics.record_latency(
490+
time.perf_counter() - start_time
491+
)
480492
return result
481493
except RecalculationNeeded:
482494
if cache_metrics:
@@ -486,7 +498,9 @@ def _call(*args, max_age: Optional[timedelta] = None, **kwds):
486498
result = _calc_entry(core, key, func, args, kwds, _print)
487499
if cache_metrics:
488500
assert start_time is not None # noqa: S101
489-
cache_metrics.record_latency(time.perf_counter() - start_time)
501+
cache_metrics.record_latency(
502+
time.perf_counter() - start_time
503+
)
490504
return result
491505
_print("No entry found. No current calc. Calling like a boss.")
492506
if cache_metrics:

src/cachier/cores/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ def _should_store(self, value: Any) -> bool:
121121

122122
def _update_size_metrics(self) -> None:
123123
"""Update cache size metrics if metrics are enabled.
124-
124+
125125
Subclasses should call this after cache modifications.
126+
126127
"""
127128
if self.metrics is None:
128129
return
@@ -137,25 +138,27 @@ def _update_size_metrics(self) -> None:
137138

138139
def _get_entry_count(self) -> int:
139140
"""Get the number of entries in the cache.
140-
141+
141142
Subclasses should override this to provide accurate counts.
142-
143+
143144
Returns
144145
-------
145146
int
146147
Number of entries in cache
148+
147149
"""
148150
return 0
149151

150152
def _get_total_size(self) -> int:
151153
"""Get the total size of the cache in bytes.
152-
154+
153155
Subclasses should override this to provide accurate sizes.
154-
156+
155157
Returns
156158
-------
157159
int
158160
Total size in bytes
161+
159162
"""
160163
return 0
161164

0 commit comments

Comments
 (0)