loader cache config

This commit is contained in:
Djeeberjr 2021-11-27 04:07:27 +01:00
parent 0971301562
commit a10593a318
2 changed files with 20 additions and 6 deletions

View File

@ -23,11 +23,18 @@ type Loader struct {
listBucketsLoaderCache cache.S3Cache listBucketsLoaderCache cache.S3Cache
} }
func NewLoader(config types.AppConfig) *Loader { type CacheConfig struct {
listObjectsLoaderCache := &dataloader.NoCache{} ListObjectsLoaderCache cache.S3Cache
listObjectsRecursiveLoaderCache := &dataloader.NoCache{} ListObjectsRecursiveLoaderCache cache.S3Cache
statObjectLoaderCache := cache.NewTTLCache(config.CacheTTL, config.CacheCleanup) StatObjectLoaderCache cache.S3Cache
listBucketsLoaderCache := cache.NewTTLCache(config.CacheTTL, config.CacheCleanup) ListBucketsLoaderCache cache.S3Cache
}
func NewLoader(cacheConfig CacheConfig) *Loader {
listObjectsLoaderCache := cacheConfig.ListObjectsLoaderCache
listObjectsRecursiveLoaderCache := cacheConfig.ListObjectsRecursiveLoaderCache
statObjectLoaderCache := cacheConfig.StatObjectLoaderCache
listBucketsLoaderCache := cacheConfig.ListBucketsLoaderCache
return &Loader{ return &Loader{
listObjectsLoader: dataloader.NewBatchedLoader( listObjectsLoader: dataloader.NewBatchedLoader(

View File

@ -3,8 +3,10 @@ package s3browser
import ( import (
"context" "context"
"github.com/graph-gophers/dataloader"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.kapelle.org/niklas/s3browser/internal/cache"
"git.kapelle.org/niklas/s3browser/internal/db" "git.kapelle.org/niklas/s3browser/internal/db"
gql "git.kapelle.org/niklas/s3browser/internal/gql" gql "git.kapelle.org/niklas/s3browser/internal/gql"
httpserver "git.kapelle.org/niklas/s3browser/internal/httpserver" 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()) 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() gql.GraphqlTypes()
schema, err := gql.GraphqlSchema() schema, err := gql.GraphqlSchema()