-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): update module github.com/hashicorp/golang-lru to v2 (#314)
* chore(deps): update module github.com/hashicorp/golang-lru to v2 * chore: Mark cache module as deprecated, update to generic version of LRU * chore: replace singleflight with implementation from golang/x/sync * chore: fix lint * chore: go mod tidy --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Carsten Dietrich <carsten.dietrich@omnevo.net>
- Loading branch information
1 parent
9e8909c
commit 29db3cf
Showing
8 changed files
with
135 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package cache_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"flamingo.me/flamingo/v3/core/cache" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_inMemoryCache_Flush(t *testing.T) { | ||
t.Parallel() | ||
|
||
inMemoryCache := cache.NewInMemoryCache() | ||
|
||
err := inMemoryCache.Set("foo", &cache.Entry{ | ||
Meta: cache.Meta{ | ||
Tags: []string{"bar"}, | ||
Lifetime: 5 * time.Second, | ||
Gracetime: 10 * time.Second, | ||
}, | ||
Data: "test", | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
err = inMemoryCache.Set("baz", &cache.Entry{ | ||
Meta: cache.Meta{ | ||
Tags: []string{"bar"}, | ||
Lifetime: 5 * time.Second, | ||
Gracetime: 10 * time.Second, | ||
}, | ||
Data: "test", | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
_, found := inMemoryCache.Get("foo") | ||
assert.True(t, found) | ||
|
||
assert.NoError(t, inMemoryCache.Flush()) | ||
|
||
_, found = inMemoryCache.Get("foo") | ||
assert.False(t, found) | ||
|
||
_, found = inMemoryCache.Get("baz") | ||
assert.False(t, found) | ||
} | ||
|
||
func Test_inMemoryCache_Purge(t *testing.T) { | ||
t.Parallel() | ||
|
||
inMemoryCache := cache.NewInMemoryCache() | ||
|
||
err := inMemoryCache.Set("foo", &cache.Entry{ | ||
Meta: cache.Meta{ | ||
Tags: []string{"bar"}, | ||
Lifetime: 5 * time.Second, | ||
Gracetime: 10 * time.Second, | ||
}, | ||
Data: "test", | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
_, found := inMemoryCache.Get("foo") | ||
assert.True(t, found) | ||
|
||
assert.NoError(t, inMemoryCache.Purge("foo")) | ||
|
||
_, found = inMemoryCache.Get("foo") | ||
assert.False(t, found) | ||
} | ||
|
||
func Test_inMemoryCache_SetGet(t *testing.T) { | ||
t.Parallel() | ||
|
||
inMemoryCache := cache.NewInMemoryCache() | ||
|
||
err := inMemoryCache.Set("foo", &cache.Entry{ | ||
Meta: cache.Meta{ | ||
Tags: []string{"bar"}, | ||
Lifetime: 5 * time.Second, | ||
Gracetime: 10 * time.Second, | ||
}, | ||
Data: "test", | ||
}) | ||
|
||
assert.NoError(t, err) | ||
|
||
entry, found := inMemoryCache.Get("foo") | ||
assert.True(t, found) | ||
assert.Equal(t, "test", entry.Data) | ||
assert.Equal(t, cache.Meta{ | ||
Tags: []string{"bar"}, | ||
Lifetime: 5 * time.Second, | ||
Gracetime: 10 * time.Second, | ||
}, entry.Meta) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.