Skip to content

Commit

Permalink
fix cached or default expression swallowing falsy value
Browse files Browse the repository at this point in the history
  • Loading branch information
FormJani committed Nov 14, 2024
1 parent 2047d22 commit 4730884
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions django_prometheus/cache/backends/django_memcached_consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get(self, key, default=None, version=None):
cached = super().get(key, default=None, version=version)
if cached is not None:
django_cache_hits_total.labels(backend="django_memcached_consul").inc()
else:
django_cache_misses_total.labels(backend="django_memcached_consul").inc()
return cached or default
return cached

django_cache_misses_total.labels(backend="django_memcached_consul").inc()
return default
7 changes: 4 additions & 3 deletions django_prometheus/cache/backends/filebased.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get(self, key, default=None, version=None):
cached = super().get(key, default=None, version=version)
if cached is not None:
django_cache_hits_total.labels(backend="filebased").inc()
else:
django_cache_misses_total.labels(backend="filebased").inc()
return cached or default
return cached

django_cache_misses_total.labels(backend="filebased").inc()
return default
7 changes: 4 additions & 3 deletions django_prometheus/cache/backends/locmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get(self, key, default=None, version=None):
cached = super().get(key, default=None, version=version)
if cached is not None:
django_cache_hits_total.labels(backend="locmem").inc()
else:
django_cache_misses_total.labels(backend="locmem").inc()
return cached or default
return cached

django_cache_misses_total.labels(backend="locmem").inc()
return default

0 comments on commit 4730884

Please sign in to comment.