| 225 | } |
| 226 | |
| 227 | func (bc *baseCache) add(key, value interface{}, entry, after *Entry) { |
| 228 | if e := bc.store.get(key); e != nil { |
| 229 | bc.access(e) |
| 230 | e.Value = value |
| 231 | return |
| 232 | } |
| 233 | e := entry |
| 234 | if e == nil { |
| 235 | e = &Entry{Key: key, Value: value} |
| 236 | } |
| 237 | if after != nil { |
| 238 | bc.ll.insertBefore(e, after) |
| 239 | } else { |
| 240 | bc.ll.pushFront(e) |
| 241 | } |
| 242 | bc.store.add(e) |
| 243 | // Evict as many elements as we can. |
| 244 | for bc.evict() { |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Get looks up a key's value from the cache. |
| 249 | func (bc *baseCache) Get(key interface{}) (value interface{}, ok bool) { |