refactor: 使用otter缓存替代buntdb,并借助context对除SQLITE以外的数据库进行细粒度缓存 #1189
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
如题,otter缓存: https://github.com/maypok86/otter;
基于对缓存和并发数据结构的研究,Otter 是 Go 最强大的缓存库之一。 Otter还借鉴了其他语言(例如caffeine )设计缓存库的经验。
同时,我现在以context创建data,logs,censor的gorm.DB,从而可以在缓存清理时,针对data/logs/censor的不同进行缓存清理,这样能增加缓存命中率。
注:由于sqlite是物理分割的,所以这个优化似乎只对PG和MYSQL有效。
另外针对Init,对应的代码要求传入context,为以后可以使用超时关闭数据库的context做准备(待定,现在反正直接传递了context.Background())