(ctx context.Context, cfg config.RecorderConfig, md *rcommon.Metadata)
| 46 | } |
| 47 | |
| 48 | func NewCacheManager(ctx context.Context, cfg config.RecorderConfig, md *rcommon.Metadata) *CacheManager { |
| 49 | mng := &CacheManager{ |
| 50 | ctx: ctx, |
| 51 | |
| 52 | metadata: md, |
| 53 | |
| 54 | cacheSetSelfHealInterval: time.Minute * time.Duration(cfg.CacheRefreshInterval), |
| 55 | SubDomainCacheMap: make(map[string]*Cache), |
| 56 | } |
| 57 | mng.DomainCache = NewCache(ctx, md, mng.cacheSetSelfHealInterval) |
| 58 | |
| 59 | var subDomains []*metadbmodel.SubDomain |
| 60 | err := mng.metadata.DB.Where(map[string]interface{}{"domain": mng.metadata.GetDomainLcuuid()}).Find(&subDomains).Error |
| 61 | if err != nil { |
| 62 | log.Errorf(dbQueryResourceFailed(ctrlrcommon.RESOURCE_TYPE_SUB_DOMAIN_EN, err), mng.metadata.LogPrefixes) |
| 63 | return mng |
| 64 | } |
| 65 | log.Infof("new sub_domain cache count: %d", len(subDomains), mng.metadata.LogPrefixes) |
| 66 | for _, subDomain := range subDomains { |
| 67 | smd := mng.metadata.Copy() |
| 68 | smd.SetSubDomain(*subDomain) |
| 69 | mng.SubDomainCacheMap[subDomain.Lcuuid] = mng.CreateSubDomainCacheIfNotExists(smd) |
| 70 | } |
| 71 | return mng |
| 72 | } |
| 73 | |
| 74 | func (m *CacheManager) CreateSubDomainCacheIfNotExists(md *rcommon.Metadata) *Cache { |
| 75 | if _, exists := m.SubDomainCacheMap[md.GetSubDomainLcuuid()]; !exists { |
nothing calls this directly
no test coverage detected