Skip to content

Commit

Permalink
add difference with hashicorp/golang-lru to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Feb 19, 2024
1 parent ec6da74 commit 208cc61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ either using LRC or LRU eviction.
run cache.DeleteExpired periodically using [time.Ticker](https://golang.org/pkg/time/#Ticker),
advisable period is 1/2 of TTL.

This cache is heavily inspired by [hashicorp/golang-lru](https://github.com/hashicorp/golang-lru) _simplelru_ implementation.
This cache is heavily inspired by [hashicorp/golang-lru](https://github.com/hashicorp/golang-lru) _simplelru_ implementation. Key differences are:

- Support LRC (Least Recently Created) in addition to LRU and TTL-based eviction
- Supports per-key TTL setting
- Doesn't spawn any goroutines, whereas `hashicorp/golang-lru/v2/expirable` spawns goroutine which is never killed ([as of now](https://github.com/hashicorp/golang-lru/issues/159))
- Provides stats about hits and misses, added and evicted entries

### Usage example

Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestCacheInvalidateAndEvict(t *testing.T) {
}

func TestCacheBadOption(t *testing.T) {
lc, err := NewCache(func(lc *cacheImpl) error {
lc, err := NewCache(func(_ *cacheImpl) error {
return fmt.Errorf("mock err")
})
assert.EqualError(t, err, "failed to set cache option: mock err")
Expand Down

0 comments on commit 208cc61

Please sign in to comment.