From fd8f81fe8651073a909f5ca310f47ca1acd68885 Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Thu, 19 Oct 2023 12:15:17 +0300 Subject: [PATCH] Added Key() method to Item --- item.go | 4 ++++ item_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/item.go b/item.go index 22ac731..013b4a5 100644 --- a/item.go +++ b/item.go @@ -55,6 +55,10 @@ func (i *Item[T]) shouldPromote(getsPerPromote int32) bool { return i.promotions == getsPerPromote } +func (i *Item[T]) Key() string { + return i.key +} + func (i *Item[T]) Value() T { return i.value } diff --git a/item_test.go b/item_test.go index c169866..63aca3e 100644 --- a/item_test.go +++ b/item_test.go @@ -8,6 +8,11 @@ import ( "github.com/karlseguin/ccache/v3/assert" ) +func Test_Item_Key(t *testing.T) { + item := &Item[int]{key: "foo"} + assert.Equal(t, item.Key(), "foo") +} + func Test_Item_Promotability(t *testing.T) { item := &Item[int]{promotions: 4} assert.Equal(t, item.shouldPromote(5), true)