MCPcopy
hub / github.com/spacecloud-io/space-cloud / SetCacheConfig

Method SetCacheConfig

gateway/managers/syncman/syncman_cache.go:15–48  ·  view source on GitHub ↗

SetCacheConfig sets the caching config

(ctx context.Context, cacheConfig *config.CacheConfig, params model.RequestParams)

Source from the content-addressed store, hash-verified

13
14// SetCacheConfig sets the caching config
15func (s *Manager) SetCacheConfig(ctx context.Context, cacheConfig *config.CacheConfig, params model.RequestParams) (int, error) {
16 // Check if the request has been hijacked
17 hookResponse := s.integrationMan.InvokeHook(ctx, params)
18 if hookResponse.CheckResponse() {
19 // Check if an error occurred
20 if err := hookResponse.Error(); err != nil {
21 return hookResponse.Status(), err
22 }
23
24 // Gracefully return
25 return hookResponse.Status(), nil
26 }
27
28 // Acquire a lock
29 s.lock.Lock()
30 defer s.lock.Unlock()
31
32 if cacheConfig.DefaultTTL == 0 {
33 cacheConfig.DefaultTTL = utils.DefaultCacheTTLTimeout
34 }
35
36 if err := s.modules.Caching().SetCachingConfig(ctx, cacheConfig); err != nil {
37 return http.StatusInternalServerError, helpers.Logger.LogError(helpers.GetRequestID(ctx), "Unable to set caching module", err, nil)
38 }
39
40 s.projectConfig.CacheConfig = cacheConfig
41
42 resourceID := config.GenerateResourceID(s.clusterID, "noProject", config.ResourceCacheConfig, "cache")
43 if err := s.store.SetResource(ctx, resourceID, cacheConfig); err != nil {
44 return http.StatusInternalServerError, err
45 }
46
47 return http.StatusOK, nil
48}
49
50// GetCacheConfig returns the cache config stored
51func (s *Manager) GetCacheConfig(ctx context.Context, params model.RequestParams) (int, interface{}, error) {

Callers 1

HandleSetCacheConfigFunction · 0.80

Calls 9

SetCachingConfigMethod · 0.80
InvokeHookMethod · 0.65
CheckResponseMethod · 0.65
ErrorMethod · 0.65
StatusMethod · 0.65
CachingMethod · 0.65
SetResourceMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected