Skip to content

Commit

Permalink
chore(deps): Maximize client side caching
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Sep 30, 2023
1 parent f640b7c commit e1a9023
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/fibr/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type services struct {
}

func newServices(ctx context.Context, config configuration, clients client, adapters adapters) (services, error) {
thumbnailService, err := thumbnail.New(config.thumbnail, adapters.storage, clients.redis, clients.telemetry.MeterProvider(), clients.telemetry.TracerProvider(), clients.amqp)
thumbnailService, err := thumbnail.New(ctx, config.thumbnail, adapters.storage, clients.redis, clients.telemetry.MeterProvider(), clients.telemetry.TracerProvider(), clients.amqp)
if err != nil {
return services{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ViBiOh/auth/v2 v2.16.1
github.com/ViBiOh/exas v0.7.1
github.com/ViBiOh/flags v1.4.1
github.com/ViBiOh/httputils/v4 v4.66.1
github.com/ViBiOh/httputils/v4 v4.66.2
github.com/ViBiOh/vith v0.6.0
github.com/rabbitmq/amqp091-go v1.8.1
github.com/redis/go-redis/v9 v9.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/ViBiOh/exas v0.7.1 h1:nzh6E1668OFRgoTIJZJa1RybCW64Gd918qi0Z+0Q4WA=
github.com/ViBiOh/exas v0.7.1/go.mod h1:MvIWQZXpWgg45Vsde9bMV48Kb0J8frya8vimmrkQ04E=
github.com/ViBiOh/flags v1.4.1 h1:qEAO70rWTYcVlU9BgCuz0SgMjth12oi502cq3SHDudg=
github.com/ViBiOh/flags v1.4.1/go.mod h1:Ocgx/QhY7WYNfGokFT3kw5C05pDooQyLbI/9ZWwylI4=
github.com/ViBiOh/httputils/v4 v4.66.1 h1:AQOJFrJIy7UjEyJgFg7Nh+F6bqkdSjNA4zDadmGyIRo=
github.com/ViBiOh/httputils/v4 v4.66.1/go.mod h1:/ZQGNMSVXvCdX127mp5iHaJ2ZN76nKPQ0vvGnta2KIc=
github.com/ViBiOh/httputils/v4 v4.66.2 h1:/Ffk99szzWL8WVRqYaJtjNPD64RoUTJ1miA5o0Qfxhg=
github.com/ViBiOh/httputils/v4 v4.66.2/go.mod h1:/ZQGNMSVXvCdX127mp5iHaJ2ZN76nKPQ0vvGnta2KIc=
github.com/ViBiOh/vith v0.6.0 h1:bdLmwgqUEWi3ivShtAhtM9gOZlWQzvZi2Z5b0BRSB1U=
github.com/ViBiOh/vith v0.6.0/go.mod h1:eRqtDU2uB8g85vll4spbnCV93DHyHNAYwXCMIBH1GuQ=
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
Expand Down
8 changes: 6 additions & 2 deletions pkg/metadata/exif.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,19 @@ func New(ctx context.Context, config *Config, storageService absto.Storage, mete
}

return service.loadExif(ctx, item)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency).WithClientSideCaching(ctx, "fibr_exif")
}, traceProvider).
WithMaxConcurrency(provider.MaxConcurrency).
WithClientSideCaching(ctx, "fibr_exif")

service.aggregateCache = cache.New(redisClient, redisKey, func(ctx context.Context, item absto.Item) (provider.Aggregate, error) {
if !item.IsDir() {
return provider.Aggregate{}, errInvalidItemType
}

return service.loadAggregate(ctx, item)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency).WithClientSideCaching(ctx, "fibr_aggregate")
}, traceProvider).
WithMaxConcurrency(provider.MaxConcurrency).
WithClientSideCaching(ctx, "fibr_aggregate")

return service, nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Flags(fs *flag.FlagSet, prefix string) *Config {
return &config
}

func New(config *Config, storage absto.Storage, redisClient redis.Client, meterProvider metric.MeterProvider, traceProvider trace.TracerProvider, amqpClient *amqp.Client) (Service, error) {
func New(ctx context.Context, config *Config, storage absto.Storage, redisClient redis.Client, meterProvider metric.MeterProvider, traceProvider trace.TracerProvider, amqpClient *amqp.Client) (Service, error) {
var amqpExchange string

if amqpClient != nil {
Expand Down Expand Up @@ -150,7 +150,9 @@ func New(config *Config, storage absto.Storage, redisClient redis.Client, meterP

service.cache = cache.New(redisClient, redisKey, func(ctx context.Context, pathname string) (absto.Item, error) {
return service.storage.Stat(ctx, pathname)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency)
}, traceProvider).
WithMaxConcurrency(provider.MaxConcurrency).
WithClientSideCaching(ctx, "fibr_thumbnail")

return service, nil
}
Expand Down

0 comments on commit e1a9023

Please sign in to comment.