This commit is contained in:
HuangJiaLuo 2021-08-21 22:27:00 +08:00
parent 7e8108bc73
commit f7abb56e92
4 changed files with 64 additions and 1 deletions

45
pkg/lru/LRU.go Normal file
View File

@ -0,0 +1,45 @@
package lru
import (
"container/list"
"gitee.com/timedb/wheatCache/pkg/lru/define"
)
type CacheNode struct {
value int
key string
}
type Cache struct {
cache map[string]*list.Element
li *list.List
size int // LRU的长度
MaxByte int64 // 允许的最大存储
NowByte int64 // 目前的存储
}
// 创建一个LRU
func NewLRU() *Cache {
return &Cache{
MaxByte: define.MaxByte,
size: 0,
NowByte: 0,
cache: make(map[string]*list.Element),
}
}
//
func GetLRU() {
}
//
func (c *Cache) AddLRU(key string, value int) {
c.size += 1
}
//获取链表长度
func (c *Cache) GetLRULength() int {
return c.size
}

View File

@ -1,3 +1,5 @@
package define
// define
const (
MaxByte = 1024
)

5
pkg/lru/test/Hello.go Normal file
View File

@ -0,0 +1,5 @@
package test
func Hello(str string) (bool, error) {
return str == "Hello", nil
}

11
pkg/lru/test/HelloTest.go Normal file
View File

@ -0,0 +1,11 @@
package test
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestHello(t *testing.T) {
_, err := Hello("Hello")
require.NoError(t, err)
}