Skip to content

Commit 283ea9b

Browse files
authored
feat(dependencies): bump to Souin v1.7.0 (#99)
* feat(dependencies): bump to Souin v1.7.0 * fix(app): remove useless provision
1 parent 9b5553f commit 283ea9b

File tree

11 files changed

+2397
-1155
lines changed

11 files changed

+2397
-1155
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
6464
- name: Run tests
6565
run: |
66-
go test -v -coverprofile="cover-profile.out" -short -race ./...
66+
go test -v -coverprofile="cover-profile.out" -race ./...
6767
6868
golangci:
6969
name: Lint

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Caddy Module: http.handlers.cache
33

44
This is a distributed HTTP cache module for Caddy based on [Souin](https://github.com/darkweak/souin) cache.
55

6+
> [!WARNING]
7+
> Since `v1.7.0` Souin (the development repository that cache-handler is based on) implements only one storage. If you need a specific storage you have to take it from [the storages repository](https://github.com/darkweak/storages) and add it either in your code, during the build otherwise.
8+
(e.g. with otter using caddy) You have to build your caddy module with the desired storage `xcaddy build --with github.com/caddyserver/cache-handler --with github.com/darkweak/storages/otter/caddy` and configure otter in your Caddyfile/JSON configuration file.
9+
See the [documentation about the storages](https://docs.souin.io/docs/storages).
10+
611
## Features
712

813
* [RFC 7234](https://httpwg.org/specs/rfc7234.html) compliant HTTP Cache.
@@ -318,22 +323,6 @@ redis-url.com {
318323

319324
You can also use the configuration. Refer to the [Souin docs](https://docs.souin.io/docs/storages/redis/)
320325
or [rueidis client options](https://github.com/redis/rueidis/blob/main/rueidis.go#L56) to define your config as key value.
321-
```
322-
redis-configuration.com {
323-
cache {
324-
redis {
325-
configuration {
326-
InitAddress 127.0.0.1:6379
327-
Username user
328-
Password password
329-
SelectDB 1
330-
ConnWriteTimeout 5s
331-
BlockingPoolSize 99999
332-
}
333-
}
334-
}
335-
}
336-
```
337326

338327
What does these directives mean?
339328
| Key | Description | Value example |

app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/darkweak/souin/configurationtypes"
88
"github.com/darkweak/souin/pkg/storage/types"
99
"github.com/darkweak/souin/pkg/surrogate/providers"
10+
"github.com/darkweak/storages/core"
1011
)
1112

1213
// SouinApp contains the whole Souin necessary items
@@ -30,6 +31,7 @@ func init() {
3031

3132
// Start will start the App
3233
func (s SouinApp) Start() error {
34+
core.ResetRegisteredStorages()
3335
_, _ = up.Delete(stored_providers_key)
3436
_, _ = up.LoadOrStore(stored_providers_key, newStorageProvider())
3537
if s.DefaultCache.GetTTL() == 0 {

cleaner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s *storage_providers) Add(key interface{}) {
2828
}
2929

3030
func (s *SouinCaddyMiddleware) Cleanup() error {
31-
s.logger.Sugar().Debug("Cleanup...")
31+
s.logger.Debug("Cleanup...")
3232
td := []interface{}{}
3333
sp, _ := up.LoadOrStore(stored_providers_key, newStorageProvider())
3434
stored_providers := sp.(*storage_providers)
@@ -43,7 +43,7 @@ func (s *SouinCaddyMiddleware) Cleanup() error {
4343
})
4444

4545
for _, v := range td {
46-
s.logger.Sugar().Debugf("Cleaning %v\n", v)
46+
s.logger.Debugf("Cleaning %v\n", v)
4747
_, _ = up.Delete(v)
4848
}
4949

configuration.go

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
1010
"github.com/darkweak/souin/configurationtypes"
11-
"go.uber.org/zap"
11+
"github.com/darkweak/storages/core"
1212
)
1313

1414
// DefaultCache the struct
@@ -38,6 +38,8 @@ type DefaultCache struct {
3838
Redis configurationtypes.CacheProvider `json:"redis"`
3939
// Etcd provider configuration.
4040
Etcd configurationtypes.CacheProvider `json:"etcd"`
41+
// Nats provider configuration.
42+
Nats configurationtypes.CacheProvider `json:"nats"`
4143
// NutsDB provider configuration.
4244
Nuts configurationtypes.CacheProvider `json:"nuts"`
4345
// Otter provider configuration.
@@ -52,6 +54,8 @@ type DefaultCache struct {
5254
TTL configurationtypes.Duration `json:"ttl"`
5355
// Stale time to live.
5456
Stale configurationtypes.Duration `json:"stale"`
57+
// Disable the coalescing system.
58+
DisableCoalescing bool `json:"disable_coalescing"`
5559
}
5660

5761
// GetAllowedHTTPVerbs returns the allowed verbs to cache
@@ -99,6 +103,11 @@ func (d *DefaultCache) GetMode() string {
99103
return d.Mode
100104
}
101105

106+
// GetNats returns nuts configuration
107+
func (d *DefaultCache) GetNats() configurationtypes.CacheProvider {
108+
return d.Nats
109+
}
110+
102111
// GetNuts returns nuts configuration
103112
func (d *DefaultCache) GetNuts() configurationtypes.CacheProvider {
104113
return d.Nuts
@@ -154,6 +163,11 @@ func (d *DefaultCache) GetMaxBodyBytes() uint64 {
154163
return d.MaxBodyBytes
155164
}
156165

166+
// IsCoalescingDisable returns if the coalescing is disabled
167+
func (d *DefaultCache) IsCoalescingDisable() bool {
168+
return d.DisableCoalescing
169+
}
170+
157171
// Configuration holder
158172
type Configuration struct {
159173
// Default cache to fallback on when none are redefined.
@@ -168,7 +182,7 @@ type Configuration struct {
168182
LogLevel string
169183
// SurrogateKeys contains the surrogate keys to use with a predefined mapping
170184
SurrogateKeys map[string]configurationtypes.SurrogateKeys
171-
logger *zap.Logger
185+
logger core.Logger
172186
}
173187

174188
// GetUrls get the urls list in the configuration
@@ -197,12 +211,12 @@ func (c *Configuration) GetLogLevel() string {
197211
}
198212

199213
// GetLogger get the logger
200-
func (c *Configuration) GetLogger() *zap.Logger {
214+
func (c *Configuration) GetLogger() core.Logger {
201215
return c.logger
202216
}
203217

204218
// SetLogger set the logger
205-
func (c *Configuration) SetLogger(l *zap.Logger) {
219+
func (c *Configuration) SetLogger(l core.Logger) {
206220
c.logger = l
207221
}
208222

@@ -269,19 +283,25 @@ func parseBadgerConfiguration(c map[string]interface{}) map[string]interface{} {
269283
func parseRedisConfiguration(c map[string]interface{}) map[string]interface{} {
270284
for k, v := range c {
271285
switch k {
272-
case "InitAddress":
286+
case "Addrs", "InitAddress":
273287
if s, ok := v.(string); ok {
274288
c[k] = []string{s}
275289
} else {
276290
c[k] = v
277291
}
278-
case "Username", "Password", "ClientName", "ClientSetInfo", "ClientTrackingOptions":
292+
case "Username", "Password", "ClientName", "ClientSetInfo", "ClientTrackingOptions", "SentinelUsername", "SentinelPassword", "MasterName", "IdentitySuffix":
279293
c[k] = v
280294
case "SendToReplicas", "ShuffleInit", "ClientNoTouch", "DisableRetry", "DisableCache", "AlwaysPipelining", "AlwaysRESP2", "ForceSingleClient", "ReplicaOnly", "ClientNoEvict":
281295
c[k] = true
282-
case "SelectDB", "CacheSizeEachConn", "RingScaleEachConn", "ReadBufferEachConn", "WriteBufferEachConn", "BlockingPoolSize", "PipelineMultiplex":
283-
c[k], _ = strconv.Atoi(v.(string))
284-
case "ConnWriteTimeout", "MaxFlushDelay":
296+
case "SelectDB", "CacheSizeEachConn", "RingScaleEachConn", "ReadBufferEachConn", "WriteBufferEachConn", "BlockingPoolSize", "PipelineMultiplex", "DB", "Protocol", "MaxRetries", "PoolSize", "MinIdleConns", "MaxIdleConns", "MaxActiveConns", "MaxRedirects":
297+
if v == false {
298+
c[k] = 0
299+
} else if v == true {
300+
c[k] = 1
301+
} else {
302+
c[k], _ = strconv.Atoi(v.(string))
303+
}
304+
case "ConnWriteTimeout", "MaxFlushDelay", "MinRetryBackoff", "MaxRetryBackoff", "DialTimeout", "ReadTimeout", "WriteTimeout", "PoolTimeout", "ConnMaxIdleTime", "ConnMaxLifetime":
285305
c[k], _ = time.ParseDuration(v.(string))
286306
}
287307
}
@@ -350,7 +370,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
350370
}
351371
cfg.API = apiConfiguration
352372
case "badger":
353-
provider := configurationtypes.CacheProvider{}
373+
provider := configurationtypes.CacheProvider{Found: true}
354374
for nesting := h.Nesting(); h.NextBlock(nesting); {
355375
directive := h.Val()
356376
switch directive {
@@ -447,7 +467,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
447467
}
448468
case "etcd":
449469
cfg.DefaultCache.Distributed = true
450-
provider := configurationtypes.CacheProvider{}
470+
provider := configurationtypes.CacheProvider{Found: true}
451471
for nesting := h.Nesting(); h.NextBlock(nesting); {
452472
directive := h.Val()
453473
switch directive {
@@ -497,8 +517,23 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
497517
return h.Errf("mode must contains only one arg: %s given", args)
498518
}
499519
cfg.DefaultCache.Mode = args[0]
520+
case "nats":
521+
provider := configurationtypes.CacheProvider{Found: true}
522+
for nesting := h.Nesting(); h.NextBlock(nesting); {
523+
directive := h.Val()
524+
switch directive {
525+
case "url":
526+
urlArgs := h.RemainingArgs()
527+
provider.URL = urlArgs[0]
528+
case "configuration":
529+
provider.Configuration = parseCaddyfileRecursively(h)
530+
default:
531+
return h.Errf("unsupported nats directive: %s", directive)
532+
}
533+
}
534+
cfg.DefaultCache.Nuts = provider
500535
case "nuts":
501-
provider := configurationtypes.CacheProvider{}
536+
provider := configurationtypes.CacheProvider{Found: true}
502537
for nesting := h.Nesting(); h.NextBlock(nesting); {
503538
directive := h.Val()
504539
switch directive {
@@ -516,7 +551,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
516551
}
517552
cfg.DefaultCache.Nuts = provider
518553
case "otter":
519-
provider := configurationtypes.CacheProvider{}
554+
provider := configurationtypes.CacheProvider{Found: true}
520555
for nesting := h.Nesting(); h.NextBlock(nesting); {
521556
directive := h.Val()
522557
switch directive {
@@ -529,7 +564,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
529564
cfg.DefaultCache.Otter = provider
530565
case "olric":
531566
cfg.DefaultCache.Distributed = true
532-
provider := configurationtypes.CacheProvider{}
567+
provider := configurationtypes.CacheProvider{Found: true}
533568
for nesting := h.Nesting(); h.NextBlock(nesting); {
534569
directive := h.Val()
535570
switch directive {
@@ -548,7 +583,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
548583
cfg.DefaultCache.Olric = provider
549584
case "redis":
550585
cfg.DefaultCache.Distributed = true
551-
provider := configurationtypes.CacheProvider{}
586+
provider := configurationtypes.CacheProvider{Found: true}
552587
for nesting := h.Nesting(); h.NextBlock(nesting); {
553588
directive := h.Val()
554589
switch directive {
@@ -615,6 +650,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
615650
if err == nil {
616651
cfg.DefaultCache.TTL.Duration = ttl
617652
}
653+
case "disable_coalescing":
654+
cfg.DefaultCache.DisableCoalescing = true
618655
default:
619656
return h.Errf("unsupported root directive: %s", rootOption)
620657
}

0 commit comments

Comments
 (0)