1. Cache2go 是什么

  • Cache2go:有心跳机制的并发安全的单机版 golang 内存数据库

2. 项目结构

  • 功能实现相关源码文件主要有 3 个:cache.go、cacheitem.go、cachetable.go

Kubernetes 学习(六)Kubernetes 源码阅读之准备篇------Cache2go 源码分析[转载]

3. 关键数据结构

  • 项目中涉及主要数据类型如下:

    • CacheItem:缓存表项
    • CacheTable:缓存表

3.1 CacheItem

  • CacheItem 类型是用来表示一个单独的缓存条目:
// CacheItem 是一个单独的缓存条目
// 参数 data 包含用户设置在缓存里的值.
type CacheItem struct {
    sync.RWMutex

    // 该项的键
    key interface{}
    // 该项的值
    data interface{}
    // 不能被访问后的存活时间
    lifeSpan time.Duration

    // 被创建的时间戳
    createdOn time.Time
    // 上一次被访问的时间戳
    accessedOn time.Time
    // 多久被访问一次
    accessCount int64

    // 被删除时触发的回调方法
    aboutToExpire []func(key interface{})
}
View Code

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-07-12
  • 2022-12-23
  • 2021-06-12
  • 2021-09-06
  • 2021-04-25
  • 2021-07-15
相关资源
相似解决方案