simplejia / lc Goto Github PK
View Code? Open in Web Editor NEWgolang local cache with concurrency control, lock free【自带并发控制,服务降级的本地kv缓存】
License: BSD 2-Clause "Simplified" License
golang local cache with concurrency control, lock free【自带并发控制,服务降级的本地kv缓存】
License: BSD 2-Clause "Simplified" License
lc.Init(50)
如果数量小于100的话,Get的时候会报错
panic: runtime error: integer divide by zero
github.com/simplejia/lc/hashmap.go:35 +0x1a8
github.com/simplejia/lc/hashmap.go
func (this *HashMap) Init(num int) *HashMap {
if this == nil {
this = new(HashMap)
}
this.blen = 100
capacity := num / this.blen * this.blen
this.bnum = capacity / this.blen
this.elems = make([]*Elem, capacity, capacity)
return this
}
这里this.blen = 100导致capacity和bnum等于0了?
func main() {
lcKey := "k"
lcValue := "v"
lc.Set(lcKey, lcValue, time.Second*3)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
go func() {
for range ticker.C {
v, ok := lc.Get(lcKey)
fmt.Println(v, ok)
}
}()
time.Sleep(time.Second*6)
}
这里设置了一个3秒过期的key,每间隔1s去get一次,输入如下:
v true
v true
v false
v true
v true
第三秒时返回false,说明正常过期,3秒后返回true?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.