@@ -29,10 +29,12 @@ import (
29
29
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
30
30
"github.com/cs3org/reva/pkg/errtypes"
31
31
"github.com/cs3org/reva/pkg/rgrpc"
32
+ "github.com/cs3org/reva/pkg/share/cache"
32
33
"github.com/cs3org/reva/pkg/sharedconf"
33
34
"github.com/cs3org/reva/pkg/token"
34
35
"github.com/cs3org/reva/pkg/token/manager/registry"
35
36
"github.com/cs3org/reva/pkg/utils/cfg"
37
+ "github.com/cs3org/reva/pkg/utils/resourceid"
36
38
"google.golang.org/grpc"
37
39
)
38
40
@@ -65,13 +67,18 @@ type config struct {
65
67
TransferExpires int64 `mapstructure:"transfer_expires"`
66
68
TokenManager string `mapstructure:"token_manager"`
67
69
// ShareFolder is the location where to create shares in the recipient's storage provider.
68
- ShareFolder string `mapstructure:"share_folder"`
69
- DataTransfersFolder string `mapstructure:"data_transfers_folder"`
70
- HomeMapping string `mapstructure:"home_mapping"`
71
- TokenManagers map [string ]map [string ]interface {} `mapstructure:"token_managers"`
72
- EtagCacheTTL int `mapstructure:"etag_cache_ttl"`
73
- AllowedUserAgents map [string ][]string `mapstructure:"allowed_user_agents"` // map[path][]user-agent
74
- CreateHomeCacheTTL int `mapstructure:"create_home_cache_ttl"`
70
+ ShareFolder string `mapstructure:"share_folder"`
71
+ DataTransfersFolder string `mapstructure:"data_transfers_folder"`
72
+ HomeMapping string `mapstructure:"home_mapping"`
73
+ TokenManagers map [string ]map [string ]interface {} `mapstructure:"token_managers"`
74
+ AllowedUserAgents map [string ][]string `mapstructure:"allowed_user_agents"` // map[path][]user-agent
75
+ CacheWarmupDriver string `mapstructure:"cache_warmup_driver"`
76
+ CacheWarmupDrivers map [string ]map [string ]interface {} `mapstructure:"cache_warmup_drivers"`
77
+ EtagCacheTTL int `mapstructure:"etag_cache_ttl"`
78
+ CreateHomeCacheTTL int `mapstructure:"create_home_cache_ttl"`
79
+ ResourceInfoCacheDriver string `mapstructure:"resource_info_cache_type"`
80
+ ResourceInfoCacheTTL int `mapstructure:"resource_info_cache_ttl"`
81
+ ResourceInfoCacheDrivers map [string ]map [string ]interface {} `mapstructure:"resource_info_caches"`
75
82
}
76
83
77
84
// sets defaults.
@@ -116,11 +123,13 @@ func (c *config) ApplyDefaults() {
116
123
}
117
124
118
125
type svc struct {
119
- c * config
120
- dataGatewayURL url.URL
121
- tokenmgr token.Manager
122
- etagCache * ttlcache.Cache `mapstructure:"etag_cache"`
123
- createHomeCache * ttlcache.Cache `mapstructure:"create_home_cache"`
126
+ c * config
127
+ dataGatewayURL url.URL
128
+ tokenmgr token.Manager
129
+ etagCache * ttlcache.Cache `mapstructure:"etag_cache"`
130
+ createHomeCache * ttlcache.Cache `mapstructure:"create_home_cache"`
131
+ resourceInfoCache cache.ResourceInfoCache
132
+ resourceInfoCacheTTL time.Duration
124
133
}
125
134
126
135
// New creates a new gateway svc that acts as a proxy for any grpc operation.
@@ -151,12 +160,21 @@ func New(ctx context.Context, m map[string]interface{}) (rgrpc.Service, error) {
151
160
_ = createHomeCache .SetTTL (time .Duration (c .CreateHomeCacheTTL ) * time .Second )
152
161
createHomeCache .SkipTTLExtensionOnHit (true )
153
162
163
+ rCache , _ := getCacheManager (c )
164
+ if c .ResourceInfoCacheTTL > 0 {
165
+ cwm , err := getCacheWarmupManager (c )
166
+ if err == nil {
167
+ go startCacheWarmup (cwm , rCache , c .ResourceInfoCacheTTL )
168
+ }
169
+ }
170
+
154
171
s := & svc {
155
- c : & c ,
156
- dataGatewayURL : * u ,
157
- tokenmgr : tokenManager ,
158
- etagCache : etagCache ,
159
- createHomeCache : createHomeCache ,
172
+ c : & c ,
173
+ dataGatewayURL : * u ,
174
+ tokenmgr : tokenManager ,
175
+ etagCache : etagCache ,
176
+ createHomeCache : createHomeCache ,
177
+ resourceInfoCache : rCache ,
160
178
}
161
179
162
180
return s , nil
@@ -217,3 +235,29 @@ func getTokenManager(manager string, m map[string]map[string]interface{}) (token
217
235
218
236
return nil , errtypes .NotFound (fmt .Sprintf ("driver %s not found for token manager" , manager ))
219
237
}
238
+
239
+ func getCacheManager (c * config.Config ) (cache.ResourceInfoCache , error ) {
240
+ if f , ok := cachereg .NewFuncs [c .ResourceInfoCacheDriver ]; ok {
241
+ return f (c .ResourceInfoCacheDrivers [c .ResourceInfoCacheDriver ])
242
+ }
243
+ return nil , fmt .Errorf ("driver not found: %s" , c .ResourceInfoCacheDriver )
244
+ }
245
+
246
+ func getCacheWarmupManager (c * config.Config ) (cache.Warmup , error ) {
247
+ if f , ok := warmupreg .NewFuncs [c .CacheWarmupDriver ]; ok {
248
+ return f (c .CacheWarmupDrivers [c .CacheWarmupDriver ])
249
+ }
250
+ return nil , fmt .Errorf ("driver not found: %s" , c .CacheWarmupDriver )
251
+ }
252
+
253
+ func startCacheWarmup (cw cache.Warmup , rCache cache.ResourceInfoCache , ttl Duration ) {
254
+ time .Sleep (2 * time .Second )
255
+ infos , err := cw .GetResourceInfos ()
256
+ if err != nil {
257
+ return
258
+ }
259
+ for _ , r := range infos {
260
+ key := resourceid .OwnCloudResourceIDWrap (r .Id )
261
+ _ = h .resourceInfoCache .SetWithExpire (key , r , h .resourceInfoCacheTTL )
262
+ }
263
+ }
0 commit comments