Skip to content

Commit 507cbf6

Browse files
authored
feat(dependencies): bump souin v1.7.5 (#111)
1 parent 283ea9b commit 507cbf6

6 files changed

Lines changed: 283 additions & 13 deletions

File tree

configuration.go

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type DefaultCache struct {
5252
Timeout configurationtypes.Timeout `json:"timeout"`
5353
// Time to live.
5454
TTL configurationtypes.Duration `json:"ttl"`
55+
// SimpleFS provider configuration.
56+
SimpleFS configurationtypes.CacheProvider `json:"simplefs"`
5557
// Stale time to live.
5658
Stale configurationtypes.Duration `json:"stale"`
5759
// Disable the coalescing system.
@@ -103,7 +105,7 @@ func (d *DefaultCache) GetMode() string {
103105
return d.Mode
104106
}
105107

106-
// GetNats returns nuts configuration
108+
// GetNats returns nats configuration
107109
func (d *DefaultCache) GetNats() configurationtypes.CacheProvider {
108110
return d.Nats
109111
}
@@ -133,6 +135,11 @@ func (d *DefaultCache) GetRegex() configurationtypes.Regex {
133135
return d.Regex
134136
}
135137

138+
// GetSimpleFS returns simplefs configuration
139+
func (d *DefaultCache) GetSimpleFS() configurationtypes.CacheProvider {
140+
return d.SimpleFS
141+
}
142+
136143
// GetStorers returns the chianed storers
137144
func (d *DefaultCache) GetStorers() []string {
138145
return d.Storers
@@ -291,7 +298,7 @@ func parseRedisConfiguration(c map[string]interface{}) map[string]interface{} {
291298
}
292299
case "Username", "Password", "ClientName", "ClientSetInfo", "ClientTrackingOptions", "SentinelUsername", "SentinelPassword", "MasterName", "IdentitySuffix":
293300
c[k] = v
294-
case "SendToReplicas", "ShuffleInit", "ClientNoTouch", "DisableRetry", "DisableCache", "AlwaysPipelining", "AlwaysRESP2", "ForceSingleClient", "ReplicaOnly", "ClientNoEvict":
301+
case "SendToReplicas", "ShuffleInit", "ClientNoTouch", "DisableRetry", "DisableCache", "AlwaysPipelining", "AlwaysRESP2", "ForceSingleClient", "ReplicaOnly", "ClientNoEvict", "ContextTimeoutEnabled", "PoolFIFO", "ReadOnly", "RouteByLatency", "RouteRandomly", "DisableIndentity":
295302
c[k] = true
296303
case "SelectDB", "CacheSizeEachConn", "RingScaleEachConn", "ReadBufferEachConn", "WriteBufferEachConn", "BlockingPoolSize", "PipelineMultiplex", "DB", "Protocol", "MaxRetries", "PoolSize", "MinIdleConns", "MaxIdleConns", "MaxActiveConns", "MaxRedirects":
297304
if v == false {
@@ -303,6 +310,45 @@ func parseRedisConfiguration(c map[string]interface{}) map[string]interface{} {
303310
}
304311
case "ConnWriteTimeout", "MaxFlushDelay", "MinRetryBackoff", "MaxRetryBackoff", "DialTimeout", "ReadTimeout", "WriteTimeout", "PoolTimeout", "ConnMaxIdleTime", "ConnMaxLifetime":
305312
c[k], _ = time.ParseDuration(v.(string))
313+
case "MaxVersion", "MinVersion":
314+
strV, _ := v.(string)
315+
if strings.HasPrefix(strV, "TLS") {
316+
strV = strings.Trim(strings.TrimPrefix(strV, "TLS"), " ")
317+
}
318+
319+
switch strV {
320+
case "0x0300", "SSLv3":
321+
c[k] = 0x0300
322+
case "0x0301", "1.0":
323+
c[k] = 0x0301
324+
case "0x0302", "1.1":
325+
c[k] = 0x0302
326+
case "0x0303", "1.2":
327+
c[k] = 0x0303
328+
case "0x0304", "1.3":
329+
c[k] = 0x0304
330+
}
331+
case "TLSConfig":
332+
c[k] = parseRedisConfiguration(v.(map[string]interface{}))
333+
}
334+
}
335+
336+
return c
337+
}
338+
339+
func parseSimpleFSConfiguration(c map[string]interface{}) map[string]interface{} {
340+
for k, v := range c {
341+
switch k {
342+
case "path":
343+
c[k] = v
344+
case "size":
345+
if v == false {
346+
c[k] = 0
347+
} else if v == true {
348+
c[k] = 1
349+
} else {
350+
c[k], _ = strconv.Atoi(v.(string))
351+
}
306352
}
307353
}
308354

@@ -441,14 +487,20 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
441487
if len(args) > 0 {
442488
cdn.Dynamic, _ = strconv.ParseBool(args[0])
443489
}
490+
case "email":
491+
cdn.Email = h.RemainingArgs()[0]
444492
case "hostname":
445493
cdn.Hostname = h.RemainingArgs()[0]
446494
case "network":
447495
cdn.Network = h.RemainingArgs()[0]
448496
case "provider":
449497
cdn.Provider = h.RemainingArgs()[0]
498+
case "service_id":
499+
cdn.ServiceID = h.RemainingArgs()[0]
450500
case "strategy":
451501
cdn.Strategy = h.RemainingArgs()[0]
502+
case "zone_id":
503+
cdn.ZoneID = h.RemainingArgs()[0]
452504
default:
453505
return h.Errf("unsupported cdn directive: %s", directive)
454506
}
@@ -531,7 +583,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
531583
return h.Errf("unsupported nats directive: %s", directive)
532584
}
533585
}
534-
cfg.DefaultCache.Nuts = provider
586+
cfg.DefaultCache.Nats = provider
535587
case "nuts":
536588
provider := configurationtypes.CacheProvider{Found: true}
537589
for nesting := h.Nesting(); h.NextBlock(nesting); {
@@ -611,6 +663,22 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
611663
return h.Errf("unsupported regex directive: %s", directive)
612664
}
613665
}
666+
case "simplefs":
667+
provider := configurationtypes.CacheProvider{Found: true}
668+
for nesting := h.Nesting(); h.NextBlock(nesting); {
669+
directive := h.Val()
670+
switch directive {
671+
case "path":
672+
urlArgs := h.RemainingArgs()
673+
provider.Path = urlArgs[0]
674+
case "configuration":
675+
provider.Configuration = parseCaddyfileRecursively(h)
676+
provider.Configuration = parseSimpleFSConfiguration(provider.Configuration.(map[string]interface{}))
677+
default:
678+
return h.Errf("unsupported simplefs directive: %s", directive)
679+
}
680+
}
681+
cfg.DefaultCache.SimpleFS = provider
614682
case "stale":
615683
args := h.RemainingArgs()
616684
stale, err := time.ParseDuration(args[0])

dispatch.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package httpcache
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67

78
"github.com/caddyserver/caddy/v2"
@@ -73,7 +74,7 @@ func (s *SouinCaddyMiddleware) parseStorages(ctx caddy.Context) {
7374
if e != nil {
7475
s.logger.Errorf("Error during Nats init, did you include the Nats storage (--with github.com/darkweak/storages/nats/caddy)? %v", e)
7576
} else {
76-
s.Configuration.DefaultCache.Nuts.Uuid = fmt.Sprintf("NATS-%s-%s", s.Configuration.DefaultCache.Nats.URL, s.Configuration.DefaultCache.GetStale())
77+
s.Configuration.DefaultCache.Nats.Uuid = fmt.Sprintf("NATS-%s-%s", s.Configuration.DefaultCache.Nats.URL, s.Configuration.DefaultCache.GetStale())
7778
}
7879
}
7980
if s.Configuration.DefaultCache.Nuts.Found {
@@ -101,7 +102,7 @@ func (s *SouinCaddyMiddleware) parseStorages(ctx caddy.Context) {
101102
if e != nil {
102103
s.logger.Errorf("Error during Olric init, did you include the Olric storage (--with github.com/darkweak/storages/olric/caddy)? %v", e)
103104
} else {
104-
s.Configuration.DefaultCache.Nuts.Uuid = fmt.Sprintf("OLRIC-%s-%s", s.Configuration.DefaultCache.Olric.URL, s.Configuration.DefaultCache.GetStale())
105+
s.Configuration.DefaultCache.Olric.Uuid = fmt.Sprintf("OLRIC-%s-%s", s.Configuration.DefaultCache.Olric.URL, s.Configuration.DefaultCache.GetStale())
105106
}
106107
}
107108
if s.Configuration.DefaultCache.Otter.Found {
@@ -121,7 +122,7 @@ func (s *SouinCaddyMiddleware) parseStorages(ctx caddy.Context) {
121122
address := redis.URL
122123
username := ""
123124
dbname := "0"
124-
cname := ""
125+
cname := "souin-redis"
125126
if c := redis.Configuration; c != nil {
126127
p, ok := c.(map[string]interface{})
127128
if ok {
@@ -172,4 +173,35 @@ func (s *SouinCaddyMiddleware) parseStorages(ctx caddy.Context) {
172173
)
173174
}
174175
}
176+
if s.Configuration.DefaultCache.SimpleFS.Found {
177+
e := dispatchStorage(ctx, "simplefs", s.Configuration.DefaultCache.SimpleFS, s.Configuration.DefaultCache.GetStale())
178+
if e != nil {
179+
s.logger.Errorf("Error during SimpleFS init, did you include the SimpleFS storage (--with github.com/darkweak/storages/simplefs/caddy)? %v", e)
180+
} else {
181+
simplefs := s.Configuration.DefaultCache.SimpleFS
182+
path := simplefs.Path
183+
size := "0"
184+
if c := simplefs.Configuration; c != nil {
185+
p, ok := c.(map[string]interface{})
186+
if ok {
187+
if d, ok := p["path"]; path == "" && ok {
188+
path = fmt.Sprint(d)
189+
}
190+
if d, ok := p["size"]; ok {
191+
size = fmt.Sprint(d)
192+
}
193+
}
194+
}
195+
196+
if path == "" {
197+
path, _ = os.Getwd()
198+
}
199+
200+
s.Configuration.DefaultCache.SimpleFS.Uuid = fmt.Sprintf(
201+
"SIMPLEFS-%s-%s",
202+
path,
203+
size,
204+
)
205+
}
206+
}
175207
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.22.1
44

55
require (
66
github.com/caddyserver/caddy/v2 v2.8.4
7-
github.com/darkweak/souin v1.7.0
8-
github.com/darkweak/storages/core v0.0.8
7+
github.com/darkweak/souin v1.7.5
8+
github.com/darkweak/storages/core v0.0.11
99
)
1010

1111
require (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
109109
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
110110
github.com/darkweak/go-esi v0.0.5 h1:b9LHI8Tz46R+i6p8avKPHAIBRQUCZDebNmKm5w/Zrns=
111111
github.com/darkweak/go-esi v0.0.5/go.mod h1:koCJqwum1u6mslyZuq/Phm6hfG1K3ZK5Y7jrUBTH654=
112-
github.com/darkweak/souin v1.7.0 h1:QeSxwHECzZPlYHTGYDw4xQ6EBJY94f/nfqW4BLc3YQ0=
113-
github.com/darkweak/souin v1.7.0/go.mod h1:XXmhB+QIiZ/lkESd1izzqCI7QWxmX0of01QA+xxgogc=
114-
github.com/darkweak/storages/core v0.0.8 h1:9e7rOxHiJwnvADDVCZ7LFRnUnOHGT+UMpNOFlR8BOiw=
115-
github.com/darkweak/storages/core v0.0.8/go.mod h1:ajTpB9IFLRIRY0EEFLjM5vtsrcNTh+TJK9yRxgG5/wY=
112+
github.com/darkweak/souin v1.7.5 h1:drNhZc0GhSbGcugiGfcYdLDTcx3DCZW6o13wwRj5o5Y=
113+
github.com/darkweak/souin v1.7.5/go.mod h1:PcP+hhvYOdqn4OmeScKKvit0TihYVYS1o154mhfWT/s=
114+
github.com/darkweak/storages/core v0.0.11 h1:IwvpAtkhOmxC5pIffJ8opW6erpTnIi5zqPveiAQs8ew=
115+
github.com/darkweak/storages/core v0.0.11/go.mod h1:ajTpB9IFLRIRY0EEFLjM5vtsrcNTh+TJK9yRxgG5/wY=
116116
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
117117
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
118118
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

httpcache.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type SouinCaddyMiddleware struct {
4747
Key configurationtypes.Key `json:"key,omitempty"`
4848
// Override the cache key generation matching the pattern.
4949
CacheKeys configurationtypes.CacheKeys `json:"cache_keys,omitempty"`
50+
// Configure the Nats cache storage.
51+
Nats configurationtypes.CacheProvider `json:"nats,omitempty"`
5052
// Configure the Nuts cache storage.
5153
Nuts configurationtypes.CacheProvider `json:"nuts,omitempty"`
5254
// Configure the Otter cache storage.
@@ -61,6 +63,8 @@ type SouinCaddyMiddleware struct {
6163
Timeout configurationtypes.Timeout `json:"timeout,omitempty"`
6264
// Time to live for a key, using time.duration.
6365
TTL configurationtypes.Duration `json:"ttl,omitempty"`
66+
// Configure the SimpleFS cache storage.
67+
SimpleFS configurationtypes.CacheProvider `json:"simplefs,omitempty"`
6468
// Time to live for a stale key, using time.duration.
6569
Stale configurationtypes.Duration `json:"stale,omitempty"`
6670
// Storage providers chaining and order.
@@ -90,7 +94,9 @@ func (s *SouinCaddyMiddleware) configurationPropertyMapper() error {
9094
if s.Configuration.GetDefaultCache() == nil {
9195
defaultCache := DefaultCache{
9296
Badger: s.Badger,
97+
Nats: s.Nats,
9398
Nuts: s.Nuts,
99+
SimpleFS: s.SimpleFS,
94100
Otter: s.Otter,
95101
Key: s.Key,
96102
DefaultCacheControl: s.DefaultCacheControl,
@@ -115,6 +121,10 @@ func (s *SouinCaddyMiddleware) configurationPropertyMapper() error {
115121
return nil
116122
}
117123

124+
func isProviderEmpty(c configurationtypes.CacheProvider) bool {
125+
return !c.Found
126+
}
127+
118128
// FromApp to initialize configuration from App structure.
119129
func (s *SouinCaddyMiddleware) FromApp(app *SouinApp) error {
120130
if s.Configuration.GetDefaultCache() == nil {
@@ -198,14 +208,16 @@ func (s *SouinCaddyMiddleware) FromApp(app *SouinApp) error {
198208
if dc.CacheName == "" {
199209
s.Configuration.DefaultCache.CacheName = appDc.CacheName
200210
}
201-
if !s.Configuration.DefaultCache.Distributed && !dc.Olric.Found && !dc.Redis.Found && !dc.Etcd.Found && !dc.Badger.Found && !dc.Nuts.Found && !dc.Otter.Found {
211+
if isProviderEmpty(dc.Badger) && isProviderEmpty(dc.Etcd) && isProviderEmpty(dc.Nats) && isProviderEmpty(dc.Nuts) && isProviderEmpty(dc.Olric) && isProviderEmpty(dc.Otter) && isProviderEmpty(dc.Redis) && isProviderEmpty(dc.SimpleFS) {
202212
s.Configuration.DefaultCache.Distributed = appDc.Distributed
203213
s.Configuration.DefaultCache.Olric = appDc.Olric
204214
s.Configuration.DefaultCache.Redis = appDc.Redis
205215
s.Configuration.DefaultCache.Etcd = appDc.Etcd
206216
s.Configuration.DefaultCache.Badger = appDc.Badger
217+
s.Configuration.DefaultCache.Nats = appDc.Nats
207218
s.Configuration.DefaultCache.Nuts = appDc.Nuts
208219
s.Configuration.DefaultCache.Otter = appDc.Otter
220+
s.Configuration.DefaultCache.SimpleFS = appDc.SimpleFS
209221
}
210222
if dc.Regex.Exclude == "" {
211223
s.Configuration.DefaultCache.Regex.Exclude = appDc.Regex.Exclude

0 commit comments

Comments
 (0)