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()