Skip to content

Commit

Permalink
Merge pull request #12 from Jrmy2402/addPrefixAndSortOnValues
Browse files Browse the repository at this point in the history
Add prefix and sort on values
  • Loading branch information
chenyahui authored May 2, 2022
2 parents 5f60432 + 2c91325 commit 635acb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func cache(

cacheKey := cacheStrategy.CacheKey

if cfg.prefixKey != "" {
cacheKey = cfg.prefixKey + cacheKey
}

// merge cfg
cacheStore := defaultCacheStore
if cacheStrategy.CacheStore != nil {
Expand Down Expand Up @@ -176,6 +180,7 @@ func getRequestUriIgnoreQueryOrder(requestURI string) (string, error) {

queryVals := make([]string, 0, len(values))
for _, queryKey := range queryKeys {
sort.Strings(values[queryKey])
for _, val := range values[queryKey] {
queryVals = append(queryVals, queryKey+"="+val)
}
Expand Down
8 changes: 8 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Config struct {
shareSingleFlightCallback OnShareSingleFlightCallback

ignoreQueryOrder bool
prefixKey string
}

func newConfigByOpts(opts ...Option) *Config {
Expand Down Expand Up @@ -128,3 +129,10 @@ func IgnoreQueryOrder() Option {
c.ignoreQueryOrder = true
}
}

// WithPrefixKey will prefix the key
func WithPrefixKey(prefix string) Option {
return func(c *Config) {
c.prefixKey = prefix
}
}

0 comments on commit 635acb3

Please sign in to comment.