github.com/cs3org/reva/v2@v2.27.7/pkg/storage/cache/createhome.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  	"strings"
    23  
    24  	userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
    25  	provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
    26  )
    27  
    28  // CreateHomeCache can invalidate all create home related cache entries
    29  type createHomeCache struct {
    30  	cacheStore
    31  }
    32  
    33  // NewCreateHomeCache creates a new CreateHomeCache
    34  func NewCreateHomeCache(cfg Config) CreateHomeCache {
    35  	c := &createHomeCache{}
    36  	c.s = getStore(cfg)
    37  	c.database = cfg.Database
    38  	c.table = cfg.Table
    39  	c.ttl = cfg.TTL
    40  
    41  	return c
    42  }
    43  
    44  // RemoveCreateHome removes a reference from the listproviders cache
    45  func (c createHomeCache) RemoveCreateHome(res *provider.ResourceId) {
    46  	if res == nil {
    47  		return
    48  	}
    49  	sid := res.SpaceId
    50  
    51  	keys, err := c.List()
    52  	if err != nil {
    53  		// FIXME log error
    54  		return
    55  	}
    56  	// FIXME add context option to List, Read and Write to upstream
    57  	for _, key := range keys {
    58  		if strings.Contains(key, sid) {
    59  			_ = c.Delete(key)
    60  			continue
    61  		}
    62  	}
    63  }
    64  
    65  func (c createHomeCache) GetKey(userID *userpb.UserId) string {
    66  	return userID.GetOpaqueId()
    67  }