Add some caching

This commit is contained in:
2021-09-17 02:01:43 +02:00
parent 36a487cb0c
commit a13e9c0eba
10 changed files with 224 additions and 123 deletions

View File

@@ -53,11 +53,13 @@ func ActionServe(c *cli.Context) error {
// Setup logging
loggers := setupLoggers(cfg)
loggers.rootLogger.Infow("Startin apiary", "version", apiary.FullVersion())
// Setup store
var s store.LoginAttemptStore
switch cfg.Store.Type {
case "MEMORY", "memory":
loggers.rootLogger.Debugw("Initializing store", "store_type", "memory")
s = &store.MemoryStore{}
case "POSTGRES", "postgres":
pgStore, err := store.NewPostgresStore(cfg.Store.Postgres.DSN)
@@ -67,7 +69,14 @@ func ActionServe(c *cli.Context) error {
if err := pgStore.InitDB(); err != nil {
return err
}
s = pgStore
if cfg.Store.EnableCache {
loggers.rootLogger.Debugw("Initializing store", "store_type", "cache-postgres")
cachingStore := store.NewCachingStore(pgStore)
s = cachingStore
} else {
loggers.rootLogger.Debugw("Initializing store", "store_type", "postgres")
s = pgStore
}
default:
return fmt.Errorf("Invalid store configured")
}