gin-contrib / cache

Gin middleware/handler to enable Cache
https://gin-gonic.github.io/gin
MIT License
378 stars 96 forks source link

[Feature Request] Add ability to ignore GET query parameters #41

Closed hashworks closed 6 years ago

hashworks commented 6 years ago

Otherwise one could always cause cache misses by adding various GET query parameters like ?foo=1.

func TestCachePageWithoutQuery(t *testing.T) {
    store := persistence.NewInMemoryStore(60 * time.Second)

    router := gin.New()
    router.GET("/cache_without_query", CachePageWithoutQuery(store, time.Second*3, func(c *gin.Context) {
        c.String(200, "pong "+fmt.Sprint(time.Now().UnixNano()))
    }))

    w1 := performRequest("GET", "/cache_without_query?foo=1", router)
    w2 := performRequest("GET", "/cache_without_query?foo=2", router)

    assert.Equal(t, 200, w1.Code)
    assert.Equal(t, 200, w2.Code)
    assert.Equal(t, w1.Body.String(), w2.Body.String())
}
appleboy commented 6 years ago

See https://github.com/gin-contrib/cache/pull/42