Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b92e16fa4d |
2
go.mod
2
go.mod
@@ -2,4 +2,4 @@ module git.wntrmute.dev/kyle/go-mru
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/benbjohnson/clock v1.3.0
|
require github.com/benbjohnson/clock v1.3.5
|
||||||
|
|||||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
|
||||||
|
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||||
4
mru.go
4
mru.go
@@ -53,6 +53,10 @@ func (c *Cache) Len() int {
|
|||||||
|
|
||||||
// evict should remove the least-recently-used cache item.
|
// evict should remove the least-recently-used cache item.
|
||||||
func (c *Cache) evict() {
|
func (c *Cache) evict() {
|
||||||
|
if c.access.Len() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
k := c.access.K(0)
|
k := c.access.K(0)
|
||||||
c.evictKey(k)
|
c.evictKey(k)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ func TestBasicCacheEviction(t *testing.T) {
|
|||||||
t.Fatal("cache should have size 0")
|
t.Fatal("cache should have size 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.evict()
|
||||||
|
if err := c.ConsistencyCheck(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
c.Store("raven", 1)
|
c.Store("raven", 1)
|
||||||
if err := c.ConsistencyCheck(); err != nil {
|
if err := c.ConsistencyCheck(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user