SetCacheConfig sets the caching config
(ctx context.Context, cacheConfig *config.CacheConfig, params model.RequestParams)
| 13 | |
| 14 | // SetCacheConfig sets the caching config |
| 15 | func (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 |
| 51 | func (s *Manager) GetCacheConfig(ctx context.Context, params model.RequestParams) (int, interface{}, error) { |
no test coverage detected