openreplay/backend/pkg/db/cache/pg-cache.go
Alexander aa3192b6c7
Patch for db and ender services (#632)
* feat(backend/db): implemented bulk inserts for db service
* feat(backend/storage): added new reading_duration metric for storage service
* feat(backend/ender): added check for sessionEnd duplicates
2022-07-21 17:22:43 +02:00

37 lines
908 B
Go

package cache
import (
"sync"
"time"
"openreplay/backend/pkg/db/postgres"
. "openreplay/backend/pkg/db/types"
)
type ProjectMeta struct {
*Project
expirationTime time.Time
}
// !TODO: remove old sessions by timeout to avoid memleaks
/*
* Cache layer around the stateless PG adapter
**/
type PGCache struct {
*postgres.Conn
sessions map[uint64]*Session
projects map[uint32]*ProjectMeta
projectsByKeys sync.Map // map[string]*ProjectMeta
projectExpirationTimeout time.Duration
}
// TODO: create conn automatically
func NewPGCache(pgConn *postgres.Conn, projectExpirationTimeoutMs int64) *PGCache {
return &PGCache{
Conn: pgConn,
sessions: make(map[uint64]*Session),
projects: make(map[uint32]*ProjectMeta),
projectExpirationTimeout: time.Duration(1000 * projectExpirationTimeoutMs),
}
}