Skip to content

Commit 44abad8

Browse files
committed
add CacheStrategyRequestURI and CacheStrategyRequestURIIgnoreQueryOrder
1 parent fd2780f commit 44abad8

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

cache.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ func CacheByRequestURI(defaultCacheStore persist.CacheStore, defaultExpire time.
168168
return cache(defaultCacheStore, defaultExpire, cfg)
169169
}
170170

171+
func CacheStrategyRequestURI(c *gin.Context) (bool, Strategy) {
172+
return true, Strategy{
173+
CacheKey: c.Request.RequestURI,
174+
}
175+
}
176+
177+
func CacheStrategyRequestURIIgnoreQueryOrder(c *gin.Context) (bool, Strategy) {
178+
newUri, err := getRequestUriIgnoreQueryOrder(c.Request.RequestURI)
179+
if err != nil {
180+
newUri = c.Request.RequestURI
181+
}
182+
183+
return true, Strategy{
184+
CacheKey: newUri,
185+
}
186+
}
187+
171188
func getRequestUriIgnoreQueryOrder(requestURI string) (string, error) {
172189
parsedUrl, err := url.ParseRequestURI(requestURI)
173190
if err != nil {

0 commit comments

Comments
 (0)