Skip to content

Commit

Permalink
feat: update ccache dep
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Oct 24, 2022
1 parent 09dee1b commit 891ee36
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ require (
github.com/alicebob/miniredis/v2 v2.18.0
github.com/bsm/redislock v0.7.2
github.com/d5/tengo/v2 v2.10.1
github.com/djherbis/stream v1.3.1
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/httplog v0.2.4
github.com/go-redis/cache/v8 v8.3.1-0.20210129151214-1cdfea0b552b
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redismock/v8 v8.0.6
github.com/google/brotli/go/cbrotli v0.0.0-20210127140805-63be8a994019
github.com/h2non/bimg v1.1.6-0.20210807160419-b29a57356338
github.com/karlseguin/ccache v2.0.3+incompatible
github.com/karlseguin/ccache/v3 v3.0.0
github.com/pkg/errors v0.9.1
github.com/pquerna/cachecontrol v0.0.0-20201205024021-ac21108117ac
github.com/prometheus/client_golang v1.9.0
Expand Down Expand Up @@ -64,7 +63,6 @@ require (
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/karlseguin/expect v1.0.7 // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/djherbis/stream v1.3.1 h1:HBT6VRIpWvzB6opRpSmHXMdWau3IOcuBhIAenBG7nN0=
github.com/djherbis/stream v1.3.1/go.mod h1:ZNVKPVRCmrwhCwQHZUpVHHrq2rtGLrG1t3T/TThYLP8=
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down Expand Up @@ -370,10 +368,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karlseguin/ccache v2.0.3+incompatible h1:j68C9tWOROiOLWTS/kCGg9IcJG+ACqn5+0+t8Oh83UU=
github.com/karlseguin/ccache v2.0.3+incompatible/go.mod h1:CM9tNPzT6EdRh14+jiW8mEF9mkNZuuE51qmgGYUB93w=
github.com/karlseguin/expect v1.0.7 h1:OF4mqjblc450v8nKARBS5Q0AweBNR0A+O3VjjpxwBrg=
github.com/karlseguin/expect v1.0.7/go.mod h1:lXdI8iGiQhmzpnnmU/EGA60vqKs8NbRNFnhhrJGoD5g=
github.com/karlseguin/ccache/v3 v3.0.0 h1:o61wYcig/e9ZbfblVRDU0SaZAUy95Hs7DbJRaydM7jo=
github.com/karlseguin/ccache/v3 v3.0.0/go.mod h1:qxC372+Qn+IBj8Pe3KvGjHPj0sWwEF7AeZVhsNPZ6uY=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg=
Expand Down Expand Up @@ -552,8 +548,6 @@ github.com/vmihailenco/msgpack/v5 v5.1.4 h1:6K44/cU6dMNGkVTGGuu7ef2NdSRFMhAFGGLf
github.com/vmihailenco/msgpack/v5 v5.1.4/go.mod h1:C5gboKD0TJPqWDTVTtrQNfRbiBwHZGo8UTqP/9/XvLI=
github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc=
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0 h1:3UeQBvD0TFrlVjOeLOBz+CPAI8dnbqNSVwUwRrkp7vQ=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
8 changes: 4 additions & 4 deletions pkg/cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/aldor007/mort/pkg/monitoring"
"github.com/aldor007/mort/pkg/object"
"github.com/aldor007/mort/pkg/response"
"github.com/karlseguin/ccache"
"github.com/karlseguin/ccache/v3"
"github.com/pkg/errors"
"go.uber.org/zap"
)

type (
// MemoryCache uses memory for cache purpose
MemoryCache struct {
cache *ccache.Cache // cache for created image transformations
cache *ccache.Cache[responseSizeProvider] // cache for created image transformations
}

// responseSizeProvider adapts response.Response to how ccache size computation requirements.
Expand Down Expand Up @@ -46,7 +46,7 @@ func (r responseSizeProvider) Size() int64 {

// NewMemoryCache returns instance of memory cache
func NewMemoryCache(maxSize int64) *MemoryCache {
return &MemoryCache{ccache.New(ccache.Configure().MaxSize(maxSize).ItemsToPrune(50))}
return &MemoryCache{ccache.New[responseSizeProvider](ccache.Configure[responseSizeProvider]().MaxSize(maxSize).ItemsToPrune(50))}
}

// Set put response to cache
Expand All @@ -66,7 +66,7 @@ func (c *MemoryCache) Get(obj *object.FileObject) (*response.Response, error) {
if cacheValue != nil {
monitoring.Log().Info("Handle Get cache", zap.String("cache", "hit"), zap.String("obj.Key", obj.Key))
monitoring.Report().Inc("cache_ratio;status:hit")
res := cacheValue.Value().(responseSizeProvider)
res := cacheValue.Value()
resCp, err := res.Copy()
if err != nil {
monitoring.Report().Inc("cache_ratio;status:miss")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (c *Config) validateServer() error {
}

if c.Server.Cache.CacheSize == 0 {
c.Server.Cache.CacheSize = 10
c.Server.Cache.CacheSize = 50000
}

if c.Server.RequestTimeout == 0 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.uber.org/zap"

"io"
"io/ioutil"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -129,7 +128,7 @@ func (r *Response) Body() ([]byte, error) {
return nil, errors.New("empty body")
}

body, err := ioutil.ReadAll(r.reader)
body, err := io.ReadAll(r.reader)
r.reader.Close()
r.reader = nil
r.setBodyBytes(body)
Expand Down
6 changes: 3 additions & 3 deletions tests-int/Cache.Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ describe('Image processing - cache', function () {
}

// If not stream mort should cache response
// if (res.headers['content-length']) {
// expect(res.headers['x-mort-cache']).to.eql('hit');
// }
if (res.headers['content-length']) {
expect(res.headers['x-mort-cache']).to.eql('hit');
}
done(err)
})
})
Expand Down
3 changes: 1 addition & 2 deletions tests-int/mort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ server:
listen: ":8091"
accessLogs: true
cache:
cacheSize: 100
maxCacheItemSizeMB: 50
maxCacheItemSizeMB: 5
plugins:
compress:
gzip:
Expand Down

0 comments on commit 891ee36

Please # to comment.