github.com/cs3org/reva/v2@v2.27.7/pkg/storage/cache/provider.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package cache 20 21 import ( 22 "sync" 23 24 userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" 25 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 26 "go-micro.dev/v4/store" 27 ) 28 29 // ProviderCache can invalidate all provider related cache entries 30 type providerCache struct { 31 cacheStore 32 } 33 34 // NewProviderCache creates a new ProviderCache 35 func NewProviderCache(cfg Config) ProviderCache { 36 c := &providerCache{} 37 c.s = getStore(cfg) 38 c.database = cfg.Database 39 c.table = cfg.Table 40 c.ttl = cfg.TTL 41 42 return c 43 } 44 45 // RemoveListStorageProviders removes a reference from the listproviders cache 46 func (c providerCache) RemoveListStorageProviders(res *provider.ResourceId) { 47 if res == nil { 48 return 49 } 50 51 keys, err := c.List(store.ListSuffix(res.SpaceId), store.ListLimit(100)) 52 if err != nil { 53 // FIXME log error 54 return 55 } 56 57 wg := sync.WaitGroup{} 58 for _, key := range keys { 59 wg.Add(1) 60 go func(k string) { 61 defer wg.Done() 62 _ = c.Delete(k) 63 }(key) 64 } 65 wg.Wait() 66 } 67 68 func (c providerCache) GetKey(userID *userpb.UserId, spaceID string) string { 69 if key := userID.GetOpaqueId() + "!" + spaceID; key != "!" { 70 return key 71 } 72 return "" 73 }