Skip to content

Commit

Permalink
Replace LRU cache package
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jun 2, 2024
1 parent b9317f8 commit c96bc14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
10 changes: 5 additions & 5 deletions spine/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ 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
}

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,
}
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit c96bc14

Please sign in to comment.