Skip to content

Commit

Permalink
Export NewItem function
Browse files Browse the repository at this point in the history
  • Loading branch information
hasfjord authored Sep 23, 2024
1 parent 09bb8f4 commit 9d01666
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c *Cache[K, V]) set(key K, value V, ttl time.Duration) *Item[K, V] {
}

// create a new item
item := newItem(key, value, ttl, c.options.enableVersionTracking)
item := NewItem(key, value, ttl, c.options.enableVersionTracking)
elem = c.items.lru.PushFront(item)
c.items.values[key] = elem
c.updateExpirations(true, elem)
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ func prepCache(ttl time.Duration, keys ...string) *Cache[string, string] {

func addToCache(c *Cache[string, string], ttl time.Duration, keys ...string) {
for i, key := range keys {
item := newItem(
item := NewItem(
key,
fmt.Sprint("value of", key),
ttl+time.Duration(i)*time.Minute,
Expand Down
4 changes: 2 additions & 2 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type Item[K comparable, V any] struct {
version int64
}

// newItem creates a new cache item.
func newItem[K comparable, V any](key K, value V, ttl time.Duration, enableVersionTracking bool) *Item[K, V] {
// NewItem creates a new cache item.
func NewItem[K comparable, V any](key K, value V, ttl time.Duration, enableVersionTracking bool) *Item[K, V] {
item := &Item[K, V]{
key: key,
value: value,
Expand Down
4 changes: 2 additions & 2 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/require"
)

func Test_newItem(t *testing.T) {
item := newItem("key", 123, time.Hour, false)
func Test_NewItem(t *testing.T) {
item := NewItem("key", 123, time.Hour, false)
require.NotNil(t, item)
assert.Equal(t, "key", item.key)
assert.Equal(t, 123, item.value)
Expand Down

0 comments on commit 9d01666

Please sign in to comment.