2020-05-18 09:32:16 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/cache"
|
|
|
|
"github.com/caos/zitadel/internal/cache/config"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
"github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
|
|
)
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
type IAMCache struct {
|
2020-05-18 09:32:16 +00:00
|
|
|
iamCache cache.Cache
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func StartCache(conf *config.CacheConfig) (*IAMCache, error) {
|
2020-05-18 09:32:16 +00:00
|
|
|
iamCache, err := conf.Config.NewCache()
|
|
|
|
logging.Log("EVENT-9siew").OnError(err).Panic("unable to create iam cache")
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
return &IAMCache{iamCache: iamCache}, nil
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (c *IAMCache) getIAM(ID string) *model.IAM {
|
|
|
|
user := &model.IAM{ObjectRoot: models.ObjectRoot{AggregateID: ID}}
|
2020-05-18 09:32:16 +00:00
|
|
|
if err := c.iamCache.Get(ID, user); err != nil {
|
|
|
|
logging.Log("EVENT-slo9x").WithError(err).Debug("error in getting cache")
|
|
|
|
}
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (c *IAMCache) cacheIAM(iam *model.IAM) {
|
2020-05-18 09:32:16 +00:00
|
|
|
err := c.iamCache.Set(iam.AggregateID, iam)
|
|
|
|
if err != nil {
|
|
|
|
logging.Log("EVENT-os03w").WithError(err).Debug("error in setting iam cache")
|
|
|
|
}
|
|
|
|
}
|