Skip to content

Commit

Permalink
Make cache response type as a private type
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed Jun 25, 2024
1 parent 103e995 commit cbb89d8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions middleware/request/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"golang.org/x/sync/singleflight"
)

type ResponseCache struct {
type responseCache struct {
data []byte
msgType wasabi.MessageType
}
Expand All @@ -20,7 +20,7 @@ type ResponseCache struct {
// The middleware caches the response of the request for a given `duration` and returns the cached response if the request is made again within the cache duration.
// If the request is made after the cache duration, the middleware forwards the request to the next handler and caches the response.
func NewCacheMiddleware(requestCache func(r wasabi.Request) (cacheKey string, ttl time.Duration)) (middleware func(next wasabi.RequestHandler) wasabi.RequestHandler, cacheCloser func()) {
cache := ttlcache.New[string, ResponseCache]()
cache := ttlcache.New[string, responseCache]()

done := make(chan struct{})
go func() {
Expand Down Expand Up @@ -48,7 +48,7 @@ func NewCacheMiddleware(requestCache func(r wasabi.Request) (cacheKey string, tt
return item.Value(), nil
}

var resp ResponseCache
var resp responseCache

connWrapper := channel.NewConnectionWrapper(conn, channel.WithSendWrapper(func(conn wasabi.Connection, msgType wasabi.MessageType, msg []byte) error {
resp.data = msg
Expand All @@ -72,7 +72,7 @@ func NewCacheMiddleware(requestCache func(r wasabi.Request) (cacheKey string, tt
return err
}

respCache, ok := resp.(ResponseCache)
respCache, ok := resp.(responseCache)
if !ok {
return fmt.Errorf("invalid response cache type")
}
Expand Down

0 comments on commit cbb89d8

Please sign in to comment.