Skip to content

Commit

Permalink
[#56] Rename Advanced to Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Mar 12, 2024
1 parent 4425ba1 commit 4fac815
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func (bs baseCache[K, V]) Stats() Stats {
return newStats(bs.cache.Stats())
}

// Advanced returns access to inspect and perform low-level operations on this cache based on its runtime
// Extension returns access to inspect and perform low-level operations on this cache based on its runtime
// characteristics. These operations are optional and dependent on how the cache was constructed
// and what abilities the implementation exposes.
func (bs baseCache[K, V]) Advanced() Advanced[K, V] {
return newAdvanced(bs.cache)
func (bs baseCache[K, V]) Extension() Extension[K, V] {
return newExtension(bs.cache)
}

// Cache is a structure performs a best-effort bounding of a hash table using eviction algorithm
Expand Down
12 changes: 6 additions & 6 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,17 @@ func TestCache_Advanced(t *testing.T) {
}

k1 := 4
v1, ok := c.Advanced().GetQuietly(k1)
v1, ok := c.Extension().GetQuietly(k1)
if !ok {
t.Fatalf("not found key %d", k1)
}

e1, ok := c.Advanced().GetEntryQuietly(k1)
e1, ok := c.Extension().GetEntryQuietly(k1)
if !ok {
t.Fatalf("not found key %d", k1)
}

e2, ok := c.Advanced().GetEntry(k1)
e2, ok := c.Extension().GetEntry(k1)
if !ok {
t.Fatalf("not found key %d", k1)
}
Expand All @@ -360,13 +360,13 @@ func TestCache_Advanced(t *testing.T) {
t.Fatalf("found not valid entries. e1: %+v, e2: %+v, v1:%d", e1, e2, v1)
}

if _, ok := c.Advanced().GetQuietly(size); ok {
if _, ok := c.Extension().GetQuietly(size); ok {
t.Fatalf("found not valid key: %d", size)
}
if _, ok := c.Advanced().GetEntryQuietly(size); ok {
if _, ok := c.Extension().GetEntryQuietly(size); ok {
t.Fatalf("found not valid key: %d", size)
}
if _, ok := c.Advanced().GetEntry(size); ok {
if _, ok := c.Extension().GetEntry(size); ok {
t.Fatalf("found not valid key: %d", size)
}
}
Expand Down
28 changes: 14 additions & 14 deletions advanced.go → extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ func zeroValue[V any]() V {
return zero
}

// Advanced is an access point for inspecting and performing low-level operations based on the cache's runtime
// Extension is an access point for inspecting and performing low-level operations based on the cache's runtime
// characteristics. These operations are optional and dependent on how the cache was constructed
// and what abilities the implementation exposes.
type Advanced[K comparable, V any] struct {
type Extension[K comparable, V any] struct {
cache *core.Cache[K, V]
}

func newAdvanced[K comparable, V any](cache *core.Cache[K, V]) Advanced[K, V] {
return Advanced[K, V]{
func newExtension[K comparable, V any](cache *core.Cache[K, V]) Extension[K, V] {
return Extension[K, V]{
cache: cache,
}
}

func (a Advanced[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] {
func (e Extension[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] {
var expiration int64
if a.cache.WithExpiration() {
if e.cache.WithExpiration() {
expiration = unixtime.StartTime() + int64(n.Expiration())
}

Expand All @@ -56,8 +56,8 @@ func (a Advanced[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] {
//
// Unlike Get in the cache, this function does not produce any side effects
// such as updating statistics or the eviction policy.
func (a Advanced[K, V]) GetQuietly(key K) (V, bool) {
n, ok := a.cache.GetNodeQuietly(key)
func (e Extension[K, V]) GetQuietly(key K) (V, bool) {
n, ok := e.cache.GetNodeQuietly(key)
if !ok {
return zeroValue[V](), false
}
Expand All @@ -66,24 +66,24 @@ func (a Advanced[K, V]) GetQuietly(key K) (V, bool) {
}

// GetEntry returns the cache entry associated with the key in this cache.
func (a Advanced[K, V]) GetEntry(key K) (Entry[K, V], bool) {
n, ok := a.cache.GetNode(key)
func (e Extension[K, V]) GetEntry(key K) (Entry[K, V], bool) {
n, ok := e.cache.GetNode(key)
if !ok {
return Entry[K, V]{}, false
}

return a.createEntry(n), true
return e.createEntry(n), true
}

// GetEntryQuietly returns the cache entry associated with the key in this cache.
//
// Unlike GetEntry, this function does not produce any side effects
// such as updating statistics or the eviction policy.
func (a Advanced[K, V]) GetEntryQuietly(key K) (Entry[K, V], bool) {
n, ok := a.cache.GetNodeQuietly(key)
func (e Extension[K, V]) GetEntryQuietly(key K) (Entry[K, V], bool) {
n, ok := e.cache.GetNodeQuietly(key)
if !ok {
return Entry[K, V]{}, false
}

return a.createEntry(n), true
return e.createEntry(n), true
}

0 comments on commit 4fac815

Please sign in to comment.