package metacache import ( "time" "gitlink.org.cn/cloudream/storage2/client/types" ) func (m *MetaCacheHost) AddStorageMeta() *UserSpaceMeta { meta := &UserSpaceMeta{} meta.cache = NewSimpleMetaCache(SimpleMetaCacheConfig[types.UserSpaceID, types.UserSpaceDetail]{ Getter: meta.load, Expire: time.Minute * 5, }) m.caches = append(m.caches, meta) return meta } type UserSpaceMeta struct { cache *SimpleMetaCache[types.UserSpaceID, types.UserSpaceDetail] } func (s *UserSpaceMeta) Get(spaceID types.UserSpaceID) *types.UserSpaceDetail { v, ok := s.cache.Get(spaceID) if ok { return &v } return nil } func (s *UserSpaceMeta) GetMany(spaceIDs []types.UserSpaceID) []*types.UserSpaceDetail { vs, oks := s.cache.GetMany(spaceIDs) ret := make([]*types.UserSpaceDetail, len(vs)) for i := range vs { if oks[i] { ret[i] = &vs[i] } } return ret } func (s *UserSpaceMeta) ClearOutdated() { s.cache.ClearOutdated() } func (s *UserSpaceMeta) load(keys []types.UserSpaceID) ([]types.UserSpaceDetail, []bool) { // vs := make([]stgmod.StorageDetail, len(keys)) // oks := make([]bool, len(keys)) // coorCli, err := stgglb.CoordinatorMQPool.Acquire() // if err != nil { // logger.Warnf("new coordinator client: %v", err) // return vs, oks // } // defer stgglb.CoordinatorMQPool.Release(coorCli) // get, err := coorCli.GetStorageDetails(coormq.ReqGetStorageDetails(keys)) // if err != nil { // logger.Warnf("get storage details: %v", err) // return vs, oks // } // for i := range keys { // if get.Storages[i] != nil { // vs[i] = *get.Storages[i] // oks[i] = true // } // } // return vs, oks }