Test_Cache_WithNoStoreRequestDirective() — fiber Function Reference
Architecture documentation for the Test_Cache_WithNoStoreRequestDirective() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 1d83c915_5096_050d_a284_17f64c97cc88["Test_Cache_WithNoStoreRequestDirective()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] 1d83c915_5096_050d_a284_17f64c97cc88 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 style 1d83c915_5096_050d_a284_17f64c97cc88 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 766–816
func Test_Cache_WithNoStoreRequestDirective(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New())
app.Get("/", func(c fiber.Ctx) error {
return c.SendString(fiber.Query(c, "id", "1"))
})
// Request id = 2
noStoreReq := httptest.NewRequest(fiber.MethodGet, "/?id=2", http.NoBody)
noStoreReq.Header.Set(fiber.HeaderCacheControl, noStore)
noStoreResp, err := app.Test(noStoreReq)
require.NoError(t, err)
noStoreBody, err := io.ReadAll(noStoreResp.Body)
require.NoError(t, err)
require.Equal(t, []byte("2"), noStoreBody)
// Response not cached, returns updated response
// Request id = 3 with Cache-Control: NO-STORE
noStoreReqUpper := httptest.NewRequest(fiber.MethodGet, "/?id=3", http.NoBody)
noStoreReqUpper.Header.Set(fiber.HeaderCacheControl, "NO-STORE")
noStoreRespUpper, err := app.Test(noStoreReqUpper)
require.NoError(t, err)
noStoreBodyUpper, err := io.ReadAll(noStoreRespUpper.Body)
require.NoError(t, err)
require.Equal(t, []byte("3"), noStoreBodyUpper)
// Response not cached, returns updated response
// Request id = 4 with Cache-Control: my-no-store
invalidReq := httptest.NewRequest(fiber.MethodGet, "/?id=4", http.NoBody)
invalidReq.Header.Set(fiber.HeaderCacheControl, "my-no-store")
invalidResp, err := app.Test(invalidReq)
require.NoError(t, err)
invalidBody, err := io.ReadAll(invalidResp.Body)
require.NoError(t, err)
require.Equal(t, cacheMiss, invalidResp.Header.Get("X-Cache"))
require.Equal(t, []byte("4"), invalidBody)
// Response cached, returns updated response, entry = 4
// Request id = 4 again without Cache-Control
cachedInvalidReq := httptest.NewRequest(fiber.MethodGet, "/?id=4", http.NoBody)
cachedInvalidResp, err := app.Test(cachedInvalidReq)
require.NoError(t, err)
cachedInvalidBody, err := io.ReadAll(cachedInvalidResp.Body)
require.NoError(t, err)
require.Equal(t, cacheHit, cachedInvalidResp.Header.Get("X-Cache"))
require.Equal(t, []byte("4"), cachedInvalidBody)
// Response cached previously, served from cache
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Cache_WithNoStoreRequestDirective() do?
Test_Cache_WithNoStoreRequestDirective() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_Cache_WithNoStoreRequestDirective() defined?
Test_Cache_WithNoStoreRequestDirective() is defined in middleware/cache/cache_test.go at line 766.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free