Skip to content

Add prefix and sort on values #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}

// PrefixKey will prefix the key
func PrefixKey(prefix string) Option {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename PrefixKey to WithPrefixKey may be more appropriate~

return func(c *Config) {
c.prefixKey = prefix
}
}