@@ -15,6 +15,8 @@ import (
1515type DefaultCache struct {
1616 // Allowed HTTP verbs to be cached by the system.
1717 AllowedHTTPVerbs []string `json:"allowed_http_verbs"`
18+ // Allowed additional status code to be cached by the system.
19+ AllowedAdditionalStatusCodes []int `json:"allowed_additional_status_codes"`
1820 // Badger provider configuration.
1921 Badger configurationtypes.CacheProvider `json:"badger"`
2022 // The cache name to use in the Cache-Status response header.
@@ -65,6 +67,11 @@ func (d *DefaultCache) GetAllowedHTTPVerbs() []string {
6567 return d .AllowedHTTPVerbs
6668}
6769
70+ // GetAllowedAdditionalStatusCodes returns the allowed verbs to cache
71+ func (d * DefaultCache ) GetAllowedAdditionalStatusCodes () []int {
72+ return d .AllowedAdditionalStatusCodes
73+ }
74+
6875// GetBadger returns the Badger configuration
6976func (d * DefaultCache ) GetBadger () configurationtypes.CacheProvider {
7077 return d .Badger
@@ -189,15 +196,17 @@ type Configuration struct {
189196 LogLevel string
190197 // SurrogateKeys contains the surrogate keys to use with a predefined mapping
191198 SurrogateKeys map [string ]configurationtypes.SurrogateKeys
192- logger core.Logger
199+ // SurrogateKeyDisabled disables the surrogate keys system
200+ SurrogateKeyDisabled bool
201+ logger core.Logger
193202}
194203
195204// GetUrls get the urls list in the configuration
196205func (c * Configuration ) GetUrls () map [string ]configurationtypes.URL {
197206 return c .URLs
198207}
199208
200- // GetDefaultCache get the default cache
209+ // GetPluginName get the plugin name
201210func (c * Configuration ) GetPluginName () string {
202211 return "caddy"
203212}
@@ -237,6 +246,11 @@ func (c *Configuration) GetSurrogateKeys() map[string]configurationtypes.Surroga
237246 return nil
238247}
239248
249+ // IsSurrogateDisabled disables the surrogate storage
250+ func (c * Configuration ) IsSurrogateDisabled () bool {
251+ return c .SurrogateKeyDisabled
252+ }
253+
240254// GetCacheKeys get the cache keys rules to override
241255func (c * Configuration ) GetCacheKeys () configurationtypes.CacheKeys {
242256 return c .CacheKeys
@@ -271,6 +285,12 @@ func parseBadgerConfiguration(c map[string]interface{}) map[string]interface{} {
271285 c [k ] = v
272286 case "SyncWrites" , "ReadOnly" , "InMemory" , "MetricsEnabled" , "CompactL0OnClose" , "LmaxCompaction" , "VerifyValueChecksum" , "BypassLockGuard" , "DetectConflicts" :
273287 c [k ] = true
288+ if v != nil {
289+ val , ok := v .(string )
290+ if ok {
291+ c [k ], _ = strconv .ParseBool (val )
292+ }
293+ }
274294 case "NumVersionsToKeep" , "NumGoroutines" , "MemTableSize" , "BaseTableSize" , "BaseLevelSize" , "LevelSizeMultiplier" , "TableSizeMultiplier" , "MaxLevels" , "ValueThreshold" , "NumMemtables" , "BlockSize" , "BlockCacheSize" , "IndexCacheSize" , "NumLevelZeroTables" , "NumLevelZeroTablesStall" , "ValueLogFileSize" , "NumCompactors" , "ZSTDCompressionLevel" , "ChecksumVerificationMode" , "NamespaceOffset" :
275295 c [k ], _ = strconv .Atoi (v .(string ))
276296 case "Compression" , "ValueLogMaxEntries" :
@@ -301,11 +321,12 @@ func parseRedisConfiguration(c map[string]interface{}) map[string]interface{} {
301321 case "SendToReplicas" , "ShuffleInit" , "ClientNoTouch" , "DisableRetry" , "DisableCache" , "AlwaysPipelining" , "AlwaysRESP2" , "ForceSingleClient" , "ReplicaOnly" , "ClientNoEvict" , "ContextTimeoutEnabled" , "PoolFIFO" , "ReadOnly" , "RouteByLatency" , "RouteRandomly" , "DisableIndentity" :
302322 c [k ] = true
303323 case "SelectDB" , "CacheSizeEachConn" , "RingScaleEachConn" , "ReadBufferEachConn" , "WriteBufferEachConn" , "BlockingPoolSize" , "PipelineMultiplex" , "DB" , "Protocol" , "MaxRetries" , "PoolSize" , "MinIdleConns" , "MaxIdleConns" , "MaxActiveConns" , "MaxRedirects" :
304- if v == false {
324+ switch v {
325+ case false :
305326 c [k ] = 0
306- } else if v == true {
327+ case true :
307328 c [k ] = 1
308- } else {
329+ default :
309330 c [k ], _ = strconv .Atoi (v .(string ))
310331 }
311332 case "ConnWriteTimeout" , "MaxFlushDelay" , "MinRetryBackoff" , "MaxRetryBackoff" , "DialTimeout" , "ReadTimeout" , "WriteTimeout" , "PoolTimeout" , "ConnMaxIdleTime" , "ConnMaxLifetime" :
@@ -342,11 +363,21 @@ func parseSimpleFSConfiguration(c map[string]interface{}) map[string]interface{}
342363 case "path" :
343364 c [k ] = v
344365 case "size" :
345- if v == false {
366+ switch v {
367+ case false :
346368 c [k ] = 0
347- } else if v == true {
369+ case true :
348370 c [k ] = 1
349- } else {
371+ default :
372+ c [k ], _ = strconv .Atoi (v .(string ))
373+ }
374+ case "directory_size" :
375+ switch v {
376+ case false :
377+ c [k ] = 0
378+ case true :
379+ c [k ] = 1
380+ default :
350381 c [k ], _ = strconv .Atoi (v .(string ))
351382 }
352383 }
@@ -364,6 +395,17 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
364395 allowed := cfg .DefaultCache .AllowedHTTPVerbs
365396 allowed = append (allowed , h .RemainingArgs ()... )
366397 cfg .DefaultCache .AllowedHTTPVerbs = allowed
398+ case "allowed_additional_status_codes" :
399+ allowed := cfg .DefaultCache .AllowedAdditionalStatusCodes
400+ additional := h .RemainingArgs ()
401+ codes := make ([]int , 0 )
402+ for _ , code := range additional {
403+ if c , err := strconv .Atoi (code ); err == nil {
404+ codes = append (codes , c )
405+ }
406+ }
407+ allowed = append (allowed , codes ... )
408+ cfg .DefaultCache .AllowedAdditionalStatusCodes = allowed
367409 case "api" :
368410 if ! isGlobal {
369411 return h .Err ("'api' block must be global" )
@@ -453,6 +495,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
453495 ck .DisableQuery = true
454496 case "disable_scheme" :
455497 ck .DisableScheme = true
498+ case "disable_vary" :
499+ ck .DisableVary = true
456500 case "template" :
457501 ck .Template = h .RemainingArgs ()[0 ]
458502 case "hash" :
@@ -547,6 +591,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
547591 config_key .DisableQuery = true
548592 case "disable_scheme" :
549593 config_key .DisableScheme = true
594+ case "disable_vary" :
595+ config_key .DisableVary = true
550596 case "template" :
551597 config_key .Template = h .RemainingArgs ()[0 ]
552598 case "hash" :
@@ -720,6 +766,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
720766 }
721767 case "disable_coalescing" :
722768 cfg .DefaultCache .DisableCoalescing = true
769+ case "disable_surrogate_key" :
770+ cfg .SurrogateKeyDisabled = true
723771 default :
724772 return h .Errf ("unsupported root directive: %s" , rootOption )
725773 }
0 commit comments