@@ -33,6 +33,23 @@ import (
3333 "golang.org/x/sync/singleflight"
3434)
3535
36+ func reorderStorers (storers []types.Storer , expectedStorers []string ) []types.Storer {
37+ if len (expectedStorers ) == 0 {
38+ return storers
39+ }
40+
41+ newStorers := make ([]types.Storer , 0 )
42+ for _ , expectedStorer := range expectedStorers {
43+ for _ , storer := range storers {
44+ if storer .Name () == strings .ToUpper (expectedStorer ) {
45+ newStorers = append (newStorers , storer )
46+ }
47+ }
48+ }
49+
50+ return newStorers
51+ }
52+
3653func NewHTTPCacheHandler (c configurationtypes.AbstractConfigurationInterface ) * SouinBaseHandler {
3754 if c .GetLogger () == nil {
3855 var logLevel zapcore.Level
@@ -75,12 +92,14 @@ func NewHTTPCacheHandler(c configurationtypes.AbstractConfigurationInterface) *S
7592 }
7693 }
7794
95+ storers = reorderStorers (storers , c .GetDefaultCache ().GetStorers ())
96+
7897 if len (storers ) > 0 {
7998 names := []string {}
8099 for _ , storer := range storers {
81100 names = append (names , storer .Name ())
82101 }
83- c .GetLogger ().Debugf ("You're running Souin with the following storages %s" , strings .Join (names , ", " ))
102+ c .GetLogger ().Debugf ("You're running Souin with the following storages in this order %s" , strings .Join (names , ", " ))
84103 }
85104 }
86105 if len (storers ) == 0 {
@@ -331,24 +350,24 @@ func (s *SouinBaseHandler) Store(
331350 }
332351 for _ , storer := range s .Storers {
333352 wg .Add (1 )
334- go func (currentStorer types.Storer ) {
353+ go func (currentStorer types.Storer , currentRes http. Response ) {
335354 defer wg .Done ()
336355 if currentStorer .SetMultiLevel (
337356 cachedKey ,
338357 variedKey ,
339358 response ,
340359 vhs ,
341- res .Header .Get ("Etag" ), ma ,
360+ currentRes .Header .Get ("Etag" ), ma ,
342361 variedKey ,
343362 ) == nil {
344363 s .Configuration .GetLogger ().Debugf ("Stored the key %s in the %s provider" , variedKey , currentStorer .Name ())
345- res .Request = rq
364+ currentRes .Request = rq
346365 } else {
347366 mu .Lock ()
348367 fails = append (fails , fmt .Sprintf ("; detail=%s-INSERTION-ERROR" , currentStorer .Name ()))
349368 mu .Unlock ()
350369 }
351- }(storer )
370+ }(storer , res )
352371 }
353372
354373 wg .Wait ()
0 commit comments