allegro / bigcache

Efficient cache for gigabytes of data written in Go.
http://allegro.tech/2016/03/writing-fast-cache-service-in-go.html
Apache License 2.0
7.45k stars 593 forks source link

feat: Add function to check if cache contains a key #382

Open Darkheir opened 10 months ago

Darkheir commented 10 months ago

Add a new function allowing to check if the cache contains the given key

janisz commented 10 months ago

Do we need this func? We have Get

Darkheir commented 10 months ago

The main difference is that Get increases the hit score of the key while Contains doesn't.

I also find it more readable to do if !cache.Contains("key") than if _, err := cache.Get("foo"); errors.Is(err, bigcache.ErrEntryNotFound)

codecov-commenter commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.31%. Comparing base (e5c39b2) to head (6a482f4). Report is 1 commits behind head on main.

:exclamation: Current head 6a482f4 differs from pull request most recent head 29b0a38

Please upload reports for the commit 29b0a38 to get more accurate results.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/allegro/bigcache/pull/382/graphs/tree.svg?width=650&height=150&src=pr&token=NRx0gXD6he&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro)](https://app.codecov.io/gh/allegro/bigcache/pull/382?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro) ```diff @@ Coverage Diff @@ ## main #382 +/- ## ========================================== + Coverage 89.08% 89.31% +0.23% ========================================== Files 15 15 Lines 797 805 +8 ========================================== + Hits 710 719 +9 Misses 73 73 + Partials 14 13 -1 ``` | [Files](https://app.codecov.io/gh/allegro/bigcache/pull/382?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro) | Coverage Δ | | |---|---|---| | [bigcache.go](https://app.codecov.io/gh/allegro/bigcache/pull/382?src=pr&el=tree&filepath=bigcache.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro#diff-YmlnY2FjaGUuZ28=) | `93.18% <100.00%> (+0.81%)` | :arrow_up: | | [shard.go](https://app.codecov.io/gh/allegro/bigcache/pull/382?src=pr&el=tree&filepath=shard.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro#diff-c2hhcmQuZ28=) | `92.22% <100.00%> (+0.20%)` | :arrow_up: | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/allegro/bigcache/pull/382?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/allegro/bigcache/pull/382?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro). Last update [a2f05d7...29b0a38](https://app.codecov.io/gh/allegro/bigcache/pull/382?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=allegro).