feat: Add caching layer to carrier connector profile repository with 5-minute TTL

- Add CachedProfileStore wrapper around PostgresProfileStore with 5-minute TTL
- Add defer close for underlying postgresRepo to ensure proper cleanup
- Rename profileRepo variable to postgresRepo for clarity before wrapping
- Add caching layer to reduce database load for profile lookups
This commit is contained in:
nutcas3
2026-04-25 05:40:09 +03:00
parent 1887901d3c
commit 4a670af341
+5 -1
View File
@@ -46,10 +46,14 @@ func main() {
if dsn == "" {
handler.Logger.Fatal().Msg("DATABASE_DSN is required (no in-memory fallback)")
}
profileRepo, err := repository.NewPostgresProfileStore(dsn)
postgresRepo, err := repository.NewPostgresProfileStore(dsn)
if err != nil {
handler.Logger.Fatal().Err(err).Msg("Failed to connect to Postgres")
}
defer postgresRepo.Close()
// Wrap with cache (5 minute TTL)
profileRepo := repository.NewCachedProfileStore(postgresRepo, 5*time.Minute)
defer profileRepo.Close()
setupRoutes(router, client, profileRepo)