github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/cache/types.go (about) 1 // Copyright 2012, Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package cache 6 7 import ( 8 "time" 9 ) 10 11 // Value that go into LRUCache need to satisfy this interface. 12 type Value interface { 13 Size() int 14 } 15 16 type Item struct { 17 Key string 18 Value interface{} 19 Size int 20 } 21 22 type entry struct { 23 key string 24 value interface{} 25 size int 26 finalizer interface{} 27 timeExpiration time.Time 28 timeAccessed time.Time 29 } 30 31 func (i *entry) Expired() bool { 32 return i.timeExpiration.Before(time.Now()) 33 } 34 35 func (i *entry) Finalize() { 36 if i.finalizer == nil { 37 return 38 } 39 if f, ok := i.finalizer.(func()); ok { 40 i.finalizer = nil 41 f() 42 return 43 } 44 if f, ok := i.finalizer.(func(x interface{})); ok { 45 i.finalizer = nil 46 f(i.value) 47 return 48 } 49 if f, ok := i.finalizer.(func(x Value)); ok { 50 i.finalizer = nil 51 f(i.value.(Value)) 52 return 53 } 54 panic("not reachable") 55 }