Skip to content

Commit ac89cca

Browse files
committed
Change a way to initialize the cache instance
1 parent 5bcad25 commit ac89cca

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ This is a modern cache implementation, **inspired** by the following papers, pro
1010

1111
This offers state-of-the-art efficiency and scalability compared to other LRU-based cache algorithms.
1212

13+
## Basic Usage
14+
```go
15+
import "github.com/scalalang2/golang-fifo/sieve"
16+
17+
size := 1e5
18+
cache := sieve.New[string, string](size)
19+
20+
cache.Set("hello", "world")
21+
val, _ := cache.Get("hello")
22+
fmt.Printf("value: %s", val) // => "world"
23+
```
24+
1325
## Benchmark Result
1426
The benchmark result were obtained using [go-cache-benchmark](https://github.com/scalalang2/go-cache-benchmark)
1527

@@ -40,18 +52,6 @@ requiring a potentially slow lock acquisition,
4052
SIEVE only needs to update a single bit upon a cache hit.
4153
This update can be done with a significantly faster reader lock, leading to increased performance.
4254

43-
## Usage
44-
```go
45-
import "github.com/scalalang2/golang-fifo/v2"
46-
47-
size := 1e5
48-
cache := fifo.NewSieve[string, string](size)
49-
50-
cache.Set("hello", "world")
51-
val, _ := cache.Get("hello")
52-
fmt.Printf("value: %s", val) // => "world"
53-
```
54-
5555
## Apendix
5656

5757
<details>

s3fifo/s3fifo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type S3FIFO[K comparable, V any] struct {
2525
ghost *bucketTable[K]
2626
}
2727

28-
func NewS3FIFO[K comparable, V any](size int) fifo.Cache[K, V] {
28+
func New[K comparable, V any](size int) fifo.Cache[K, V] {
2929
return &S3FIFO[K, V]{
3030
size: size,
3131
items: make(map[K]*s3fifoEntry[V]),

s3fifo/s3fifo_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestSetAndGetOnCache(t *testing.T) {
10-
cache := NewS3FIFO[string, string](10)
10+
cache := New[string, string](10)
1111
cache.Set("hello", "world")
1212

1313
value, ok := cache.Get("hello")
@@ -16,7 +16,7 @@ func TestSetAndGetOnCache(t *testing.T) {
1616
}
1717

1818
func TestEvictOneHitWonders(t *testing.T) {
19-
cache := NewS3FIFO[int, int](10)
19+
cache := New[int, int](10)
2020
oneHitWonders := []int{1, 2}
2121
popularObjects := []int{3, 4, 5, 6, 7, 8, 9, 10}
2222

@@ -61,7 +61,7 @@ func TestEvictOneHitWonders(t *testing.T) {
6161
}
6262

6363
func TestPeekOnCache(t *testing.T) {
64-
cache := NewS3FIFO[int, int](5)
64+
cache := New[int, int](5)
6565
entries := []int{1, 2, 3, 4, 5}
6666

6767
for _, v := range entries {
@@ -93,7 +93,7 @@ func TestPeekOnCache(t *testing.T) {
9393
}
9494

9595
func TestContainsOnCache(t *testing.T) {
96-
cache := NewS3FIFO[int, int](5)
96+
cache := New[int, int](5)
9797
entries := []int{1, 2, 3, 4, 5}
9898

9999
for _, v := range entries {
@@ -111,7 +111,7 @@ func TestContainsOnCache(t *testing.T) {
111111
}
112112

113113
func TestLengthOnCache(t *testing.T) {
114-
cache := NewS3FIFO[string, string](10)
114+
cache := New[string, string](10)
115115

116116
cache.Set("hello", "world")
117117
require.Equal(t, 1, cache.Len())
@@ -126,7 +126,7 @@ func TestLengthOnCache(t *testing.T) {
126126
}
127127

128128
func TestCleanOnCache(t *testing.T) {
129-
cache := NewS3FIFO[int, int](10)
129+
cache := New[int, int](10)
130130
entries := []int{1, 2, 3, 4, 5}
131131

132132
for _, v := range entries {

sieve/sieve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Sieve[K comparable, V any] struct {
2121
hand *list.Element
2222
}
2323

24-
func NewSieve[K comparable, V any](size int) fifo.Cache[K, V] {
24+
func New[K comparable, V any](size int) fifo.Cache[K, V] {
2525
return &Sieve[K, V]{
2626
size: size,
2727
items: make(map[K]*list.Element),

sieve/sieve_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func TestGetAndSetOnSieve(t *testing.T) {
1010
items := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
11-
cache := NewSieve[int, int](10)
11+
cache := New[int, int](10)
1212

1313
for _, v := range items {
1414
cache.Set(v, v*10)
@@ -22,15 +22,15 @@ func TestGetAndSetOnSieve(t *testing.T) {
2222
}
2323

2424
func TestContainsOnSieve(t *testing.T) {
25-
cache := NewSieve[string, string](10)
25+
cache := New[string, string](10)
2626
require.False(t, cache.Contains("hello"))
2727

2828
cache.Set("hello", "world")
2929
require.True(t, cache.Contains("hello"))
3030
}
3131

3232
func TestLenOnSieve(t *testing.T) {
33-
cache := NewSieve[int, int](10)
33+
cache := New[int, int](10)
3434
require.Equal(t, 0, cache.Len())
3535

3636
cache.Set(1, 1)

0 commit comments

Comments
 (0)