File tree Expand file tree Collapse file tree 1 file changed +4
-11
lines changed Expand file tree Collapse file tree 1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change @@ -8,27 +8,23 @@ type Cache struct {
88 nbytes int64
99 ll * list.List
1010 cache map [string ]* list.Element
11- // optional and executed when an entry is purged.
12- OnEvicted func (key string , value Value )
1311}
1412
1513type entry struct {
1614 key string
1715 value Value
1816}
1917
20- // Value use Len to count how many bytes it takes
2118type Value interface {
2219 Len () int
2320}
2421
2522// New is the Constructor of Cache
26- func New (maxBytes int64 , onEvicted func ( string , Value ) ) * Cache {
23+ func New (maxBytes int64 ) * Cache {
2724 return & Cache {
28- maxBytes : maxBytes ,
29- ll : list .New (),
30- cache : make (map [string ]* list.Element ),
31- OnEvicted : onEvicted ,
25+ maxBytes : maxBytes ,
26+ ll : list .New (),
27+ cache : make (map [string ]* list.Element ),
3228 }
3329}
3430
@@ -67,9 +63,6 @@ func (c *Cache) RemoveOldest() {
6763 kv := ele .Value .(* entry )
6864 delete (c .cache , kv .key )
6965 c .nbytes -= int64 (len (kv .key )) + int64 (kv .value .Len ())
70- if c .OnEvicted != nil {
71- c .OnEvicted (kv .key , kv .value )
72- }
7366 }
7467}
7568
You can’t perform that action at this time.
0 commit comments