golang-lru
golang-lru copied to clipboard
Added AddOrUpdate method to lru
It behaves similar to the standard Add method with the difference that it can also take an update method that will be performed in case the key already exists.
For example:
value1 := []string{"some_value"}
value2 := []string{"some_value_2"}
l.Add(1, value1)
l.AddOrUpdate(1, value2, func(v1, v2 interface{}) interface{} {
slice1 := v1.([]string)
slice2 := v2.([]string)
return append(slice1, slice2...)
})
Then l.Get(1) will result to
[]string{"some_value", "some_value_2"}