コード例 #1
0
ファイル: lru.go プロジェクト: jumpzhangpng/golang-lru
// NewWithEvict constructs a fixed size cache with the given eviction
// callback.
func NewWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error) {
	lru, err := simplelru.NewLRU(size, simplelru.EvictCallback(onEvicted))
	if err != nil {
		return nil, err
	}
	c := &Cache{
		lru: lru,
	}
	return c, nil
}
コード例 #2
0
ファイル: cache.go プロジェクト: tarent/lib-compose
// NewCache creates a new cache
func NewCache(name string, maxEntries int, maxSizeMB int, maxAge time.Duration) *Cache {
	c := &Cache{
		name:         name,
		maxAge:       maxAge,
		maxSizeBytes: maxSizeMB * 1024 * 1024,
	}

	var err error
	c.lruBackend, err = simplelru.NewLRU(maxEntries, simplelru.EvictCallback(c.onEvicted))
	if err != nil {
		panic(err)
	}
	return c
}