Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

工程应用实例 #146

Open
hunterhug opened this issue Sep 27, 2021 · 0 comments
Open

工程应用实例 #146

hunterhug opened this issue Sep 27, 2021 · 0 comments

Comments

@hunterhug
Copy link
Owner

https://github.com/hunterhug/gocache/blob/master/README_ZH.md

该库使用了红黑树和最小堆数据结构。利用最小堆堆顶是最老的值,从而快速清洗过期值。可以认为是一个有过期时间的 K-V 本地内存数据库。

原理很简单:

一个 treeMap 用来保存 K-V,一个最小堆的完全树用来清洗过期 key。
官方的 map 不会缩容,treemap 的话不会占用多余空间。
开了个定时器惰性删除过期key,由于定时器每秒最多清除30个过期,可能不够实时,所以当客户端主动拿值时会进行实时删除key,参考的redis。

@hunterhug hunterhug pinned this issue Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant