Skip to content

Commit ade978f

Browse files
authored
Merge pull request #5 from Code-Hex/fix/signature-new
fixed signature New -> NewCache
2 parents 5dafec6 + 2684ffa commit ade978f

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545

4646
func main() {
4747
// Create a simple cache. key as string, value as int.
48-
simpleCache := simple.New[string, int](simple.WithExpiration(time.Hour))
48+
simpleCache := simple.NewCache[string, int](simple.WithExpiration(time.Hour))
4949

5050
// Create a cache for Number constraint. key as string, value as int.
5151
nc := cache.NewNumber[string, int](simpleCache)

cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestMultiThreadIncr(t *testing.T) {
12-
nc := cache.NewNumber[string, int](simple.New[string, int]())
12+
nc := cache.NewNumber[string, int](simple.NewCache[string, int]())
1313
nc.Set("counter", 0)
1414

1515
var wg sync.WaitGroup
@@ -30,7 +30,7 @@ func TestMultiThreadIncr(t *testing.T) {
3030
}
3131

3232
func TestMultiThreadDecr(t *testing.T) {
33-
nc := cache.NewNumber[string, int](simple.New[string, int]())
33+
nc := cache.NewNumber[string, int](simple.NewCache[string, int]())
3434
nc.Set("counter", 100)
3535

3636
var wg sync.WaitGroup

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func ExampleNumberCache() {
11-
c := cache.NewNumber[string, int](simple.New[string, int]())
11+
c := cache.NewNumber[string, int](simple.NewCache[string, int]())
1212
c.Set("a", 1)
1313
c.Set("b", 2)
1414
av := c.Increment("a", 1)

lru/example_test.go

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

99
func ExampleLRUCache() {
10-
c := lru.New[string, int]()
10+
c := lru.NewCache[string, int]()
1111
c.Set("a", 1)
1212
c.Set("b", 2)
1313
av, aok := c.Get("a")
@@ -23,7 +23,7 @@ func ExampleLRUCache() {
2323
}
2424

2525
func ExampleCacheKeys() {
26-
c := lru.New[string, int]()
26+
c := lru.NewCache[string, int]()
2727
c.Set("a", 1)
2828
c.Set("b", 2)
2929
c.Set("c", 3)

lru/lru.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ type item[K comparable, V any] struct {
2222
Value V
2323
}
2424

25-
// New creates a new LRU cache whose capacity is the default size (128).
26-
func New[K comparable, V any]() *Cache[K, V] {
27-
return NewCap[K, V](128)
25+
// NewCache creates a new LRU cache whose capacity is the default size (128).
26+
func NewCache[K comparable, V any]() *Cache[K, V] {
27+
return NewCacheWithCap[K, V](128)
2828
}
2929

30-
// NewCap creates a new LRU cache whose capacity is the specified size.
31-
func NewCap[K comparable, V any](cap int) *Cache[K, V] {
30+
// NewCacheWithCap creates a new LRU cache whose capacity is the specified size.
31+
func NewCacheWithCap[K comparable, V any](cap int) *Cache[K, V] {
3232
return &Cache[K, V]{
3333
cap: cap,
3434
list: list.New(),

lru/lru_test.go

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

99
func TestSet(t *testing.T) {
1010
// set capacity is 1
11-
cache := lru.NewCap[string, int](1)
11+
cache := lru.NewCacheWithCap[string, int](1)
1212
cache.Set("foo", 1)
1313
if got := cache.Len(); got != 1 {
1414
t.Fatalf("invalid length: %d", got)
@@ -44,7 +44,7 @@ func TestSet(t *testing.T) {
4444
}
4545

4646
func TestContains(t *testing.T) {
47-
cache := lru.New[string, int]()
47+
cache := lru.NewCache[string, int]()
4848
cache.Set("foo", 1)
4949
cache.Set("bar", 2)
5050
cache.Set("baz", 3)
@@ -60,7 +60,7 @@ func TestContains(t *testing.T) {
6060
}
6161

6262
func TestDelete(t *testing.T) {
63-
cache := lru.NewCap[string, int](1)
63+
cache := lru.NewCacheWithCap[string, int](1)
6464
cache.Set("foo", 1)
6565
if got := cache.Len(); got != 1 {
6666
t.Fatalf("invalid length: %d", got)

simple/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func ExampleCache() {
12-
c := simple.New[string, int](simple.WithExpiration(time.Hour))
12+
c := simple.NewCache[string, int](simple.WithExpiration(time.Hour))
1313
c.Set("a", 1)
1414
c.Set("b", 2)
1515
av, aok := c.Get("a")
@@ -25,7 +25,7 @@ func ExampleCache() {
2525
}
2626

2727
func ExampleCacheKeys() {
28-
c := simple.New[string, int]()
28+
c := simple.NewCache[string, int]()
2929
c.Set("a", 1)
3030
c.Set("b", 2)
3131
c.Set("c", 3)

simple/simple.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type Cache[K comparable, V any] struct {
4444

4545
var _ cache.Cache[interface{}, any] = (*Cache[interface{}, any])(nil)
4646

47-
// New creates a new cache.
48-
func New[K comparable, V any](opts ...Option) *Cache[K, V] {
47+
// NewCache creates a new cache.
48+
func NewCache[K comparable, V any](opts ...Option) *Cache[K, V] {
4949
o := new(options)
5050
for _, optFunc := range opts {
5151
optFunc(o)

simple/simple_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestHasExpired(t *testing.T) {
5959
}
6060

6161
func TestGetItemExpired(t *testing.T) {
62-
c := New[struct{}, int]()
62+
c := NewCache[struct{}, int]()
6363
c.SetItem(struct{}{}, &Item[int]{
6464
Value: 1,
6565
Expiration: time.Hour * 24,

0 commit comments

Comments
 (0)