• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-pkgz / expirable-cache / 42665437761
100%

Build:
DEFAULT BRANCH: master
Ran 09 Nov 2026 05:31PM UTC
Jobs 1
Files 2
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

09 Nov 2026 05:31PM UTC coverage: 100.0%. Remained the same
42665437761

push

github

web-flow
Add ContainsOrAdd to v3 Cache (#30)

* Add ContainsOrAdd to v3 Cache

Contains and Add each take the lock on their own, so two goroutines can
both miss a key and both insert it, and the second write silently replaces
the first. Callers needed their own mutex around the pair. ContainsOrAdd
does the check and the insert under one lock, with the same signature as
hashicorp's lru.Cache.

A found key changes nothing: no recency move and no stats. An expired
entry counts as missing and is replaced the same way Add updates an
existing key. Adding the method to the Cache interface breaks anyone who
implements Cache outside the package; v1 and v2 stay unchanged.

Fixed #17

* Read the clock under the lock in ContainsOrAdd

ContainsOrAdd took the time before waiting for the lock. An entry that
expired during the wait, for example behind a slow onEvicted callback, was
still treated as live and the insert was skipped. Contains and Get already
read the clock after locking.

The concurrency test started 100 goroutines on one key with no start
barrier, so they rarely overlapped, and a Contains-then-Add implementation
failed it in 4 of 100 runs. Eight workers now start together and walk the
same 1000 keys, which fails that implementation in 100 of 100 runs.

168 of 168 relevant lines covered (100.0%)

137.08 hits per line

Jobs
ID Job ID Ran Files Coverage
1 42665437761.1 09 Nov 2026 05:31PM UTC 2
100.0
GitHub Action Run
Source Files on build 42665437761
  • Tree
  • List 2
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 8772bc2f on github
  • Prev Build on master (#42661718550)
  • Next Build on master (#42665440530)
  • Delete
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc