Commit e691ee9 1 parent caa11ec commit e691ee9 Copy full SHA for e691ee9
File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -61,15 +61,16 @@ func New(maxElementCount int) Cache {
61
61
}
62
62
63
63
func (c * lruCache ) Add (node Node ) Node {
64
- if e , exists := c .dict [string (node .GetKey ())]; exists {
64
+ key := string (node .GetKey ())
65
+ if e , exists := c .dict [key ]; exists {
65
66
c .ll .MoveToFront (e )
66
67
old := e .Value
67
68
e .Value = node
68
69
return old .(Node )
69
70
}
70
71
71
72
elem := c .ll .PushFront (node )
72
- c .dict [string ( node . GetKey ()) ] = elem
73
+ c .dict [key ] = elem
73
74
74
75
if c .ll .Len () > c .maxElementCount {
75
76
oldest := c .ll .Back ()
@@ -96,8 +97,9 @@ func (c *lruCache) Len() int {
96
97
}
97
98
98
99
func (c * lruCache ) Remove (key []byte ) Node {
99
- if elem , exists := c .dict [string (key )]; exists {
100
- return c .remove (elem )
100
+ keyS := string (key )
101
+ if elem , exists := c .dict [keyS ]; exists {
102
+ return c .removeWithKey (elem , keyS )
101
103
}
102
104
return nil
103
105
}
@@ -107,3 +109,9 @@ func (c *lruCache) remove(e *list.Element) Node {
107
109
delete (c .dict , ibytes .UnsafeBytesToStr (removed .GetKey ()))
108
110
return removed
109
111
}
112
+
113
+ func (c * lruCache ) removeWithKey (e * list.Element , key string ) Node {
114
+ removed := c .ll .Remove (e ).(Node )
115
+ delete (c .dict , key )
116
+ return removed
117
+ }
You can’t perform that action at this time.
0 commit comments