From a10593a3185816cbfc6d9ccebb2291db1d796a08 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sat, 27 Nov 2021 04:07:27 +0100 Subject: [PATCH] loader cache config --- internal/loader/loader.go | 17 ++++++++++++----- internal/s3Broswer.go | 9 ++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/loader/loader.go b/internal/loader/loader.go index 281af04..499e942 100644 --- a/internal/loader/loader.go +++ b/internal/loader/loader.go @@ -23,11 +23,18 @@ type Loader struct { listBucketsLoaderCache cache.S3Cache } -func NewLoader(config types.AppConfig) *Loader { - listObjectsLoaderCache := &dataloader.NoCache{} - listObjectsRecursiveLoaderCache := &dataloader.NoCache{} - statObjectLoaderCache := cache.NewTTLCache(config.CacheTTL, config.CacheCleanup) - listBucketsLoaderCache := cache.NewTTLCache(config.CacheTTL, config.CacheCleanup) +type CacheConfig struct { + ListObjectsLoaderCache cache.S3Cache + ListObjectsRecursiveLoaderCache cache.S3Cache + StatObjectLoaderCache cache.S3Cache + ListBucketsLoaderCache cache.S3Cache +} + +func NewLoader(cacheConfig CacheConfig) *Loader { + listObjectsLoaderCache := cacheConfig.ListObjectsLoaderCache + listObjectsRecursiveLoaderCache := cacheConfig.ListObjectsRecursiveLoaderCache + statObjectLoaderCache := cacheConfig.StatObjectLoaderCache + listBucketsLoaderCache := cacheConfig.ListBucketsLoaderCache return &Loader{ listObjectsLoader: dataloader.NewBatchedLoader( diff --git a/internal/s3Broswer.go b/internal/s3Broswer.go index b9d9c06..5411536 100644 --- a/internal/s3Broswer.go +++ b/internal/s3Broswer.go @@ -3,8 +3,10 @@ package s3browser import ( "context" + "github.com/graph-gophers/dataloader" log "github.com/sirupsen/logrus" + "git.kapelle.org/niklas/s3browser/internal/cache" "git.kapelle.org/niklas/s3browser/internal/db" gql "git.kapelle.org/niklas/s3browser/internal/gql" httpserver "git.kapelle.org/niklas/s3browser/internal/httpserver" @@ -33,7 +35,12 @@ func Start(config types.AppConfig) { log.Error("Failed to connect DB: ", err.Error()) } - loader := loader.NewLoader(config) + loader := loader.NewLoader(loader.CacheConfig{ + ListObjectsLoaderCache: &dataloader.NoCache{}, + ListObjectsRecursiveLoaderCache: &dataloader.NoCache{}, + StatObjectLoaderCache: cache.NewTTLCache(config.CacheTTL, config.CacheCleanup), + ListBucketsLoaderCache: cache.NewTTLCache(config.CacheTTL, config.CacheCleanup), + }) gql.GraphqlTypes() schema, err := gql.GraphqlSchema()