diff --git a/README.md b/README.md index 78260ea53..341545a6f 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ surrogate_keys: | `default_cache.badger.configuration` | Configure Badger directly in the Caddyfile or your JSON caddy configuration | [See the Badger configuration for the options](https://dgraph.io/docs/badger/get-started/) | | `default_cache.headers` | List of headers to include to the cache | `- Authorization`

`- Content-Type`

`- X-Additional-Header` | | `default_cache.olric` | Configure the Olric cache storage | | -| `default_cache.olric.path` | Configure Olric with a file | `/anywhere/badger_configuration.json` | -| `default_cache.olric.configuration` | Configure Olric directly in the Caddyfile or your JSON caddy configuration | [See the Badger configuration for the options](https://github.com/buraksezer/olric/blob/master/cmd/olricd/olricd.yaml/) | +| `default_cache.olric.path` | Configure Olric with a file | `/anywhere/olric_configuration.json` | +| `default_cache.olric.configuration` | Configure Olric directly in the Caddyfile or your JSON caddy configuration | [See the Olric configuration for the options](https://github.com/buraksezer/olric/blob/master/cmd/olricd/olricd.yaml/) | | `default_cache.port.{web,tls}` | The device's local HTTP/TLS port that Souin should be listening on | Respectively `80` and `443` | | `default_cache.regex.exclude` | The regex used to prevent paths being cached | `^[A-z]+.*$` | | `default_cache.stale` | The stale duration | `25m` | @@ -225,7 +225,7 @@ Supported providers - [Olric](https://github.com/buraksezer/olric) The cache system sits on top of three providers at the moment. It provides an in-memory, redis and Olric cache systems because setting, getting, updating and deleting keys in these providers is as easy as it gets. - In order to do that, Redis and Olric providers need to be either on the same network as the Souin instance when using docker-compose or over the internet, then it will use by default in-memory to avoid network latency as much as possible. + In order to do that, the Olric provider need to be either on the same network as the Souin instance when using docker-compose or over the internet, then it will use by default in-memory to avoid network latency as much as possible. Souin will return at first the in-memory response when it gives a non-empty response, then the olric one followed by the redis one with same condition, or fallback to the reverse proxy otherwise. Since v1.4.2, Souin supports [Olric](https://github.com/buraksezer/olric) to handle distributed cache. @@ -332,9 +332,6 @@ There is the fully configuration below } badger { path the_path_to_a_file.json - configuration { - # Your badger configuration here - } } cdn { api_key XXXX @@ -375,16 +372,79 @@ respond "Hello World!" cache @match { ttl 5s + badger { + path /tmp/badger/first-match + configuration { + # Required value + ValueDir + + # Optional + SyncWrites + NumVersionsToKeep + ReadOnly + Compression + InMemory + MetricsEnabled + MemTableSize + BaseTableSize + BaseLevelSize + LevelSizeMultiplier + TableSizeMultiplier + MaxLevels + VLogPercentile + ValueThreshold + NumMemtables + BlockSize + BloomFalsePositive + BlockCacheSize + IndexCacheSize + NumLevelZeroTables + NumLevelZeroTablesStall + ValueLogFileSize + ValueLogMaxEntries + NumCompactors + CompactL0OnClose + LmaxCompaction + ZSTDCompressionLevel + VerifyValueChecksum + EncryptionKey + EncryptionKey + BypassLockGuard + ChecksumVerificationMode + DetectConflicts + NamespaceOffset + } + } } cache @match2 { ttl 50s + badger { + path /tmp/badger/second-match + configuration { + ValueDir match2 + ValueLogFileSize 16777216 + MemTableSize 4194304 + ValueThreshold 524288 + BypassLockGuard true + } + } headers Authorization default_cache_control "public, max-age=86400" } cache @matchdefault { ttl 5s + badger { + path /tmp/badger/default-match + configuration { + ValueDir default + ValueLogFileSize 16777216 + MemTableSize 4194304 + ValueThreshold 524288 + BypassLockGuard true + } + } } cache @souin-api {} @@ -455,7 +515,6 @@ func main() { } ``` - After that you will be able to declare the httpcache filter in your eskip file. ``` hello: Path("/hello") @@ -472,7 +531,7 @@ experimental: plugins: souin: moduleName: github.com/darkweak/souin - version: v1.6.1 + version: v1.6.2 ``` After that you can declare either the whole configuration at once in the middleware block or by service. See the examples below. ```yaml @@ -615,7 +674,6 @@ A repository called [prestashop-souin](https://github.com/lucmichalski/prestasho ### Wordpress plugin A repository called [wordpress-souin](https://github.com/Darkweak/wordpress-souin) to be able to manage your Souin instance through the admin panel UI. - ## Credits Thanks to these users for contributing or helping this project in any way diff --git a/plugins/caddy/README.md b/plugins/caddy/README.md index cd70909ad..b9e02b425 100644 --- a/plugins/caddy/README.md +++ b/plugins/caddy/README.md @@ -10,7 +10,6 @@ This is a distributed HTTP cache module for Caddy based on [Souin](https://githu * REST API to purge the cache and list stored resources. * Builtin support for distributed cache. - ## Example Configurations There is the fully configuration below ```caddy @@ -30,9 +29,6 @@ There is the fully configuration below } badger { path the_path_to_a_file.json - configuration { - # Your badger configuration here - } } cdn { api_key XXXX @@ -73,16 +69,79 @@ respond "Hello World!" cache @match { ttl 5s + badger { + path /tmp/badger/first-match + configuration { + # Required value + ValueDir + + # Optional + SyncWrites + NumVersionsToKeep + ReadOnly + Compression + InMemory + MetricsEnabled + MemTableSize + BaseTableSize + BaseLevelSize + LevelSizeMultiplier + TableSizeMultiplier + MaxLevels + VLogPercentile + ValueThreshold + NumMemtables + BlockSize + BloomFalsePositive + BlockCacheSize + IndexCacheSize + NumLevelZeroTables + NumLevelZeroTablesStall + ValueLogFileSize + ValueLogMaxEntries + NumCompactors + CompactL0OnClose + LmaxCompaction + ZSTDCompressionLevel + VerifyValueChecksum + EncryptionKey + EncryptionKey + BypassLockGuard + ChecksumVerificationMode + DetectConflicts + NamespaceOffset + } + } } cache @match2 { ttl 50s + badger { + path /tmp/badger/second-match + configuration { + ValueDir match2 + ValueLogFileSize 16777216 + MemTableSize 4194304 + ValueThreshold 524288 + BypassLockGuard true + } + } headers Authorization default_cache_control "public, max-age=86400" } cache @matchdefault { ttl 5s + badger { + path /tmp/badger/default-match + configuration { + ValueDir default + ValueLogFileSize 16777216 + MemTableSize 4194304 + ValueThreshold 524288 + BypassLockGuard true + } + } } cache @souin-api {} @@ -111,8 +170,8 @@ What does these directives mean? | `default_cache_control` | Set the default value of `Cache-Control` response header if not set by upstream (Souin treats empty `Cache-Control` as `public` if omitted) | `no-store` | | `headers` | List of headers to include to the cache | `Authorization Content-Type X-Additional-Header` | | `olric` | Configure the Olric cache storage | | -| `olric.path` | Configure Olric with a file | `/anywhere/badger_configuration.json` | -| `olric.configuration` | Configure Olric directly in the Caddyfile or your JSON caddy configuration | [See the Badger configuration for the options](https://github.com/buraksezer/olric/blob/master/cmd/olricd/olricd.yaml/) | +| `olric.path` | Configure Olric with a file | `/anywhere/olric_configuration.json` | +| `olric.configuration` | Configure Olric directly in the Caddyfile or your JSON caddy configuration | [See the Olric configuration for the options](https://github.com/buraksezer/olric/blob/master/cmd/olricd/olricd.yaml/) | | `regex.exclude` | The regex used to prevent paths being cached | `^[A-z]+.*$` | | `stale` | The stale duration | `25m` | | `ttl` | The TTL duration | `120s` | @@ -123,7 +182,6 @@ Other resources You can find an example for the [Caddyfile](Caddyfile) or the [JSON file](configuration.json). See the [Souin](https://github.com/darkweak/souin) configuration for the full configuration, and its associated [Caddyfile](https://github.com/darkweak/souin/blob/master/plugins/caddy/Caddyfile) - ## TODO * [ ] Improve the API and add relevant endpoints diff --git a/plugins/caddy/go.mod b/plugins/caddy/go.mod index 74e1c25e9..ac5366ec5 100644 --- a/plugins/caddy/go.mod +++ b/plugins/caddy/go.mod @@ -4,8 +4,8 @@ go 1.16 require ( github.com/caddyserver/caddy/v2 v2.4.5 - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 go.uber.org/zap v1.19.1 ) -replace github.com/darkweak/souin v1.6.1 => ../.. +replace github.com/darkweak/souin v1.6.2 => ../.. diff --git a/plugins/caddy/httpcache.go b/plugins/caddy/httpcache.go index 29b89e578..608c04b50 100644 --- a/plugins/caddy/httpcache.go +++ b/plugins/caddy/httpcache.go @@ -26,7 +26,6 @@ type key string const getterContextCtxKey key = "getter_context" const moduleName = "cache" -const moduleID caddy.ModuleID = "http.handlers." + moduleName func init() { caddy.RegisterModule(SouinCaddyPlugin{}) @@ -52,7 +51,7 @@ type SouinCaddyPlugin struct { // CaddyModule returns the Caddy module information. func (SouinCaddyPlugin) CaddyModule() caddy.ModuleInfo { return caddy.ModuleInfo{ - ID: moduleID, + ID: "http.handlers.cache", New: func() caddy.Module { return new(SouinCaddyPlugin) }, } } @@ -244,7 +243,7 @@ func parseBadgerConfiguration(c map[string]interface{}) map[string]interface{} { case "Dir", "ValueDir": c[k] = v case "SyncWrites", "ReadOnly", "InMemory", "MetricsEnabled", "CompactL0OnClose", "LmaxCompaction", "VerifyValueChecksum", "BypassLockGuard", "DetectConflicts": - c[k], _ = strconv.ParseBool(v.(string)) + c[k] = true case "NumVersionsToKeep", "NumGoroutines", "MemTableSize", "BaseTableSize", "BaseLevelSize", "LevelSizeMultiplier", "TableSizeMultiplier", "MaxLevels", "ValueThreshold", "NumMemtables", "BlockSize", "BlockCacheSize", "IndexCacheSize", "NumLevelZeroTables", "NumLevelZeroTablesStall", "ValueLogFileSize", "NumCompactors", "ZSTDCompressionLevel", "ChecksumVerificationMode", "NamespaceOffset": c[k], _ = strconv.Atoi(v.(string)) case "Compression", "ValueLogMaxEntries": diff --git a/plugins/echo/go.mod b/plugins/echo/go.mod index 91e9913eb..6d7e887af 100644 --- a/plugins/echo/go.mod +++ b/plugins/echo/go.mod @@ -3,9 +3,9 @@ module github.com/darkweak/souin/plugins/echo go 1.16 require ( - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 github.com/labstack/echo/v4 v4.6.1 go.uber.org/zap v1.19.1 ) -replace github.com/darkweak/souin v1.6.1 => ../.. +replace github.com/darkweak/souin v1.6.2 => ../.. diff --git a/plugins/gin/go.mod b/plugins/gin/go.mod index 5e6df4e8a..29c6de7c6 100644 --- a/plugins/gin/go.mod +++ b/plugins/gin/go.mod @@ -3,7 +3,7 @@ module github.com/darkweak/souin/plugins/gin go 1.16 require ( - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 github.com/gin-gonic/gin v1.7.7 github.com/go-playground/validator/v10 v10.10.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -14,4 +14,4 @@ require ( google.golang.org/protobuf v1.27.1 // indirect ) -replace github.com/darkweak/souin v1.6.1 => ../.. +replace github.com/darkweak/souin v1.6.2 => ../.. diff --git a/plugins/skipper/go.mod b/plugins/skipper/go.mod index ef13e3cf9..ac6e7a810 100644 --- a/plugins/skipper/go.mod +++ b/plugins/skipper/go.mod @@ -3,9 +3,9 @@ module github.com/darkweak/souin/plugins/skipper go 1.16 require ( - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 github.com/zalando/skipper v0.13.174 go.uber.org/zap v1.19.1 ) -replace github.com/darkweak/souin v1.6.1 => ../.. +replace github.com/darkweak/souin v1.6.2 => ../.. diff --git a/plugins/traefik/go.mod b/plugins/traefik/go.mod index 1c43c83da..2aaada744 100644 --- a/plugins/traefik/go.mod +++ b/plugins/traefik/go.mod @@ -3,10 +3,10 @@ module github.com/darkweak/souin/plugins/traefik go 1.16 require ( - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pquerna/cachecontrol v0.1.0 go.uber.org/zap v1.19.1 ) -replace github.com/darkweak/souin v1.6.1 => ../.. +replace github.com/darkweak/souin v1.6.2 => ../.. diff --git a/plugins/traefik/vendor/modules.txt b/plugins/traefik/vendor/modules.txt index 3f10c2ae6..87756aa60 100644 --- a/plugins/traefik/vendor/modules.txt +++ b/plugins/traefik/vendor/modules.txt @@ -39,7 +39,7 @@ github.com/buraksezer/olric/stats github.com/cespare/xxhash # github.com/cespare/xxhash/v2 v2.1.2 github.com/cespare/xxhash/v2 -# github.com/darkweak/souin v1.6.1 => ../.. +# github.com/darkweak/souin v1.6.2 => ../.. ## explicit github.com/darkweak/souin/api github.com/darkweak/souin/api/auth diff --git a/plugins/tyk/go.mod b/plugins/tyk/go.mod index 31eb1fb86..5fe56bd3f 100644 --- a/plugins/tyk/go.mod +++ b/plugins/tyk/go.mod @@ -6,7 +6,7 @@ require ( github.com/TykTechnologies/gojsonschema v0.0.0-20170222154038-dcb3e4bb7990 // indirect github.com/TykTechnologies/tyk v2.9.5+incompatible github.com/clbanning/mxj v1.8.4 // indirect - github.com/darkweak/souin v1.6.1 + github.com/darkweak/souin v1.6.2 github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf // indirect github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8 // indirect github.com/hashicorp/terraform v1.0.1 // indirect @@ -22,6 +22,6 @@ require ( ) replace ( - github.com/darkweak/souin v1.6.1 => ../.. + github.com/darkweak/souin v1.6.2 => ../.. github.com/hashicorp/terraform v1.0.1 => github.com/hashicorp/terraform v0.14.11 )