cache2go开源项目的回调使用

https://github.com/muesli/cache2go

结构体

type CacheTable struct {
    sync.RWMutex
.
    name string
    items map[interface{}]*CacheItem

    cleanupTimer *time.Timer
    cleanupInterval time.Duration

    logger *log.Logger

    // 回调方法定义
    loadData func(key interface{}, args ...interface{}) *CacheItem
    addedItem func(item *CacheItem)
    aboutToDeleteItem func(item *CacheItem)
}

回调方法

func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem)) {
    table.Lock()
    defer table.Unlock()
        // 回调方法赋值f函数对象
    table.addedItem = f 

猜你喜欢

转载自www.cnblogs.com/liujitao79/p/9963583.html