From c96bc14d05b081e395e7f13f7d54147629d585d5 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Sun, 2 Jun 2024 12:34:22 +0200 Subject: [PATCH] Replace LRU cache package --- go.mod | 2 +- go.sum | 4 ++-- spine/send.go | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 9248204..bb354e6 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.21.1 require ( github.com/ahmetb/go-linq/v3 v3.2.0 github.com/enbility/ship-go v0.5.0 + github.com/golanguzb70/lrucache v1.2.0 github.com/google/go-cmp v0.6.0 - github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/rickb777/date v1.20.5 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index cfab5e6..067858c 100644 --- a/go.sum +++ b/go.sum @@ -5,10 +5,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/enbility/ship-go v0.5.0 h1:Uqol2XjzDOcvT8HUAE4B/59yqd3mxhpJJ/Q2eDHNGqc= github.com/enbility/ship-go v0.5.0/go.mod h1:ovyrJE3oPnGT5+eQnOqWut80gFDQ0XHn3ZWU2fHV9xQ= +github.com/golanguzb70/lrucache v1.2.0 h1:VjpjmB4VTf9VXBtZTJGcgcN0CNFM5egDrrSjkGyQOlg= +github.com/golanguzb70/lrucache v1.2.0/go.mod h1:zc2GD26KwGEDdTHsCCTcJorv/11HyKwQVS9gqg2bizc= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= -github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/spine/send.go b/spine/send.go index ea9f1d6..b3843d6 100644 --- a/spine/send.go +++ b/spine/send.go @@ -10,14 +10,14 @@ import ( "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/util" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/golanguzb70/lrucache" ) type Sender struct { msgNum uint64 // 64bit values need to be defined on top of the struct to make atomic commands work on 32bit systems // we cache the last 100 notify messages, so we can find the matching item for result errors being returned - datagramNotifyCache *lru.Cache[model.MsgCounterType, model.DatagramType] + datagramNotifyCache *lrucache.LRUCache[model.MsgCounterType, model.DatagramType] writeHandler shipapi.ShipConnectionDataWriterInterface } @@ -25,9 +25,9 @@ type Sender struct { var _ api.SenderInterface = (*Sender)(nil) func NewSender(writeI shipapi.ShipConnectionDataWriterInterface) api.SenderInterface { - cache, _ := lru.New[model.MsgCounterType, model.DatagramType](100) + cache := lrucache.New[model.MsgCounterType, model.DatagramType](100, 0) return &Sender{ - datagramNotifyCache: cache, + datagramNotifyCache: &cache, writeHandler: writeI, } } @@ -184,7 +184,7 @@ func (c *Sender) Notify(senderAddress, destinationAddress *model.FeatureAddressT }, } - c.datagramNotifyCache.Add(*msgCounter, datagram) + c.datagramNotifyCache.Put(*msgCounter, datagram) return msgCounter, c.sendSpineMessage(datagram) }