diff --git a/README.md b/README.md index d8fa3de63..143bb654b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ default_cache: # Required port: # Ports on which Souin will be exposed web: 80 tls: 443 - ttl: 10 # Default TTL + ttl: 10s # Default TTL reverse_proxy_url: 'http://traefik' # If it's in the same network you can use http://your-service, otherwise just use https://yourdomain.com ``` This is a fully working minimal configuration for a Souin instance @@ -78,18 +78,19 @@ default_cache: url: 'olric:3320' # Olric server regex: exclude: 'ARegexHere' # Regex to exclude from cache + ttl: 1000s # Default TTL log_level: INFO # Logs verbosity [ DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL ], case do not matter ssl_providers: # The {providers}.json to use - traefik urls: 'https:\/\/domain.com\/first-.+': # First regex route configuration - ttl: 1000 # Override default TTL + ttl: 1000s # Override default TTL 'https:\/\/domain.com\/second-route': # Second regex route configuration - ttl: 10 # Override default TTL + ttl: 10s # Override default TTL headers: # Override default headers - Authorization 'https?:\/\/mysubdomain\.domain\.com': # Third regex route configuration - ttl: 50 # Override default TTL + ttl: 50s # Override default TTL headers: # Override default headers - Authorization - 'Content-Type' diff --git a/cache/providers/olricProvider.go b/cache/providers/olricProvider.go index cbd317858..bb1a6591f 100644 --- a/cache/providers/olricProvider.go +++ b/cache/providers/olricProvider.go @@ -1,11 +1,11 @@ package providers import ( + "fmt" "github.com/buraksezer/olric/client" "github.com/buraksezer/olric/config" "github.com/darkweak/souin/cache/keysaver" t "github.com/darkweak/souin/configurationtypes" - "strconv" "time" ) @@ -64,8 +64,12 @@ func (provider *Olric) Get(key string) []byte { // Set method will store the response in Redis provider func (provider *Olric) Set(key string, value []byte, url t.URL, duration time.Duration) { if duration == 0 { - ttl, _ := strconv.Atoi(url.TTL) - duration = time.Duration(ttl) * time.Second + ttl, err := time.ParseDuration(url.TTL) + if err != nil { + ttl = 0 + fmt.Println(err) + } + duration = ttl } err := provider.dm.PutEx(key, value, duration) diff --git a/cache/providers/ristrettoProvider.go b/cache/providers/ristrettoProvider.go index cf495fbfe..69379dc03 100644 --- a/cache/providers/ristrettoProvider.go +++ b/cache/providers/ristrettoProvider.go @@ -1,10 +1,10 @@ package providers import ( + "fmt" "github.com/darkweak/souin/cache/keysaver" t "github.com/darkweak/souin/configurationtypes" "github.com/dgraph-io/ristretto" - "strconv" "time" ) @@ -55,8 +55,12 @@ func (provider *Ristretto) Get(key string) []byte { // Set method will store the response in Ristretto provider func (provider *Ristretto) Set(key string, value []byte, url t.URL, duration time.Duration) { if duration == 0 { - ttl, _ := strconv.Atoi(url.TTL) - duration = time.Duration(ttl) * time.Second + ttl, err := time.ParseDuration(url.TTL) + if err != nil { + ttl = 0 + fmt.Println(err) + } + duration = ttl } isSet := provider.SetWithTTL(key, value, 1, duration) if !isSet { diff --git a/configuration/configuration.sample.yml b/configuration/configuration.sample.yml index 9aaad970e..acc1e5481 100644 --- a/configuration/configuration.sample.yml +++ b/configuration/configuration.sample.yml @@ -20,20 +20,20 @@ default_cache: # Required part tls: 443 regex: # Regex configuration exclude: 'ARegexHere' # Regex to exclude from cache - ttl: 10 # Default TTL + ttl: 10s # Default TTL log_level: INFO # Logs verbosity [ DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, debug, info, warn, error, dpanic, panic, fatal ] reverse_proxy_url: 'http://traefik' # If it's in the same network you can use http://your-service. Then just use https://yourdomain.com ssl_providers: # The {providers}.json to usee - traefik urls: 'https:\/\/domain.com\/first-.+': # First regex route configuration - ttl: 1000 # Override default TTL + ttl: 1000s # Override default TTL 'https:\/\/domain.com\/second-route': # Second regex route configuration - ttl: 10 # Override default TTL + ttl: 10s # Override default TTL headers: # Override default headers - Authorization 'https?:\/\/mysubdomain\.domain\.com': # Third regex route configuration - ttl: 50 + ttl: 50s headers: # Override default headers - Authorization - 'Content-Type' diff --git a/configuration/configuration.yml b/configuration/configuration.yml index 7f55d1981..521fd1f0f 100644 --- a/configuration/configuration.yml +++ b/configuration/configuration.yml @@ -17,18 +17,18 @@ default_cache: tls: 443 regex: exclude: 'ARegexHere' - ttl: 10 + ttl: 10s log_level: debug reverse_proxy_url: 'http://traefik' ssl_providers: - traefik urls: 'domain.com/testing': - ttl: 100 + ttl: 100s headers: - Authorization 'mysubdomain.domain.com': - ttl: 50 + ttl: 50s headers: - Authorization - 'Content-Type'