| # This file reports differences detected by import.go since the last import. |
| # This is only for human review and not machine consumption. |
| # Please see go/thirdpartygo for more information. |
| # DO NOT EDIT. This must only be generated by //third_party/golang/import.go. |
| |
| @@ type ARCCache struct { |
| size int // Size is the total capacity of the cache |
| p int // P is the dynamic preference towards T1 or T2 |
| |
| - t1 simplelru.LRUCache // T1 is the LRU for recently accessed items |
| - b1 simplelru.LRUCache // B1 is the LRU for evictions from t1 |
| + t1 *simplelru.LRU // T1 is the LRU for recently accessed items |
| + b1 *simplelru.LRU // B1 is the LRU for evictions from t1 |
| |
| - t2 simplelru.LRUCache // T2 is the LRU for frequently accessed items |
| - b2 simplelru.LRUCache // B2 is the LRU for evictions from t2 |
| + t2 *simplelru.LRU // T2 is the LRU for frequently accessed items |
| + b2 *simplelru.LRU // B2 is the LRU for evictions from t2 |
| |
| lock sync.RWMutex |
| } |
| |
| // NewARC creates an ARC of the given size |
| func NewARC(size int) (*ARCCache, error) { |
| + return NewARCWithEvict(size, nil) |
| +} |
| + |
| +// NewARCWithEvict creates an ARC of the given size with onEvict callback. |
| +func NewARCWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*ARCCache, error) { |
| + callback := simplelru.EvictCallback(onEvicted) |
| // Create the sub LRUs |
| b1, err := simplelru.NewLRU(size, nil) |
| if err != nil { |
| @@ func NewARC(size int) (*ARCCache, error) { |
| if err != nil { |
| return nil, err |
| } |
| - t1, err := simplelru.NewLRU(size, nil) |
| + t1, err := simplelru.NewLRU(size, callback) |
| if err != nil { |
| return nil, err |
| } |
| - t2, err := simplelru.NewLRU(size, nil) |
| + t2, err := simplelru.NewLRU(size, callback) |
| if err != nil { |
| return nil, err |
| } |
| @@ func (c *ARCCache) Get(key interface{}) (value interface{}, ok bool) { |
| // If the value is contained in T1 (recent), then |
| // promote it to T2 (frequent) |
| if val, ok := c.t1.Peek(key); ok { |
| - c.t1.Remove(key) |
| + c.t1.RemoveWithoutEvict(key) |
| c.t2.Add(key, val) |
| return val, ok |
| } |
| @@ func (c *ARCCache) Add(key, value interface{}) { |
| // Check if the value is contained in T1 (recent), and potentially |
| // promote it to frequent T2 |
| if c.t1.Contains(key) { |
| - c.t1.Remove(key) |
| + c.t1.RemoveWithoutEvict(key) |
| c.t2.Add(key, value) |
| return |
| } |
| @@ func (c *ARCCache) Keys() []interface{} { |
| return append(k1, k2...) |
| } |
| |
| +func (c *ARCCache) subcaches() [4]simplelru.LRUCache { |
| + return [4]simplelru.LRUCache{c.t1, c.t2, c.b1, c.b2} |
| +} |
| + |
| // Remove is used to purge a key from the cache |
| func (c *ARCCache) Remove(key interface{}) { |
| c.lock.Lock() |
| defer c.lock.Unlock() |
| - if c.t1.Remove(key) { |
| - return |
| - } |
| - if c.t2.Remove(key) { |
| - return |
| - } |
| - if c.b1.Remove(key) { |
| - return |
| - } |
| - if c.b2.Remove(key) { |
| - return |
| + for _, cache := range c.subcaches() { |
| + if cache.Remove(key) { |
| + return |
| + } |
| } |
| } |
| |
| @@ func (c *ARCCache) Remove(key interface{}) { |
| func (c *ARCCache) Purge() { |
| c.lock.Lock() |
| defer c.lock.Unlock() |
| - c.t1.Purge() |
| - c.t2.Purge() |
| - c.b1.Purge() |
| - c.b2.Purge() |
| + for _, cache := range c.subcaches() { |
| + cache.Purge() |
| + } |
| } |
| |
| // Contains is used to check if the cache contains a key |