Test_Cache_WithETagAndNoCacheRequestDirective() — fiber Function Reference
Architecture documentation for the Test_Cache_WithETagAndNoCacheRequestDirective() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 50b98640_1f5e_1f05_4a63_39c1124165b8["Test_Cache_WithETagAndNoCacheRequestDirective()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] 50b98640_1f5e_1f05_4a63_39c1124165b8 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 style 50b98640_1f5e_1f05_4a63_39c1124165b8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 690–763
func Test_Cache_WithETagAndNoCacheRequestDirective(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(
etag.New(),
New(),
)
app.Get("/", func(c fiber.Ctx) error {
return c.SendString(fiber.Query(c, "id", "1"))
})
// Request id = 1
req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
resp, err := app.Test(req)
require.NoError(t, err)
require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusOK, resp.StatusCode)
// Response cached, entry id = 1
// If response status 200
etagToken := resp.Header.Get("Etag")
// Request id = 2 with ETag but without Cache-Control: no-cache
cachedReq := httptest.NewRequest(fiber.MethodGet, "/?id=2", http.NoBody)
cachedReq.Header.Set(fiber.HeaderIfNoneMatch, etagToken)
cachedResp, err := app.Test(cachedReq)
require.NoError(t, err)
require.Equal(t, cacheHit, cachedResp.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusNotModified, cachedResp.StatusCode)
// Response not cached, returns cached response, entry id = 1, status not modified
// Request id = 2 with ETag and Cache-Control: no-cache
noCacheReq := httptest.NewRequest(fiber.MethodGet, "/?id=2", http.NoBody)
noCacheReq.Header.Set(fiber.HeaderCacheControl, noCache)
noCacheReq.Header.Set(fiber.HeaderIfNoneMatch, etagToken)
noCacheResp, err := app.Test(noCacheReq)
require.NoError(t, err)
require.Equal(t, cacheMiss, noCacheResp.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusOK, noCacheResp.StatusCode)
// Response cached, returns updated response, entry id = 2
// If response status 200
etagToken = noCacheResp.Header.Get("Etag")
// Request id = 3 with ETag and Cache-Control: NO-CACHE
noCacheReqUpper := httptest.NewRequest(fiber.MethodGet, "/?id=3", http.NoBody)
noCacheReqUpper.Header.Set(fiber.HeaderCacheControl, "NO-CACHE")
noCacheReqUpper.Header.Set(fiber.HeaderIfNoneMatch, etagToken)
noCacheRespUpper, err := app.Test(noCacheReqUpper)
require.NoError(t, err)
require.Equal(t, cacheMiss, noCacheRespUpper.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusOK, noCacheRespUpper.StatusCode)
// Response cached, returns updated response, entry id = 3
// Request id = 2 with ETag and Cache-Control: no-cache again
noCacheReq1 := httptest.NewRequest(fiber.MethodGet, "/?id=2", http.NoBody)
noCacheReq1.Header.Set(fiber.HeaderCacheControl, noCache)
noCacheReq1.Header.Set(fiber.HeaderIfNoneMatch, etagToken)
noCacheResp1, err := app.Test(noCacheReq1)
require.NoError(t, err)
require.Equal(t, cacheMiss, noCacheResp1.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusNotModified, noCacheResp1.StatusCode)
// Response cached, returns updated response, entry id = 2, status not modified
// Request id = 1 without ETag and Cache-Control: no-cache
cachedReq1 := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
cachedResp1, err := app.Test(cachedReq1)
require.NoError(t, err)
require.Equal(t, cacheHit, cachedResp1.Header.Get("X-Cache"))
require.Equal(t, fiber.StatusOK, cachedResp1.StatusCode)
// Response not cached, returns cached response, entry id = 2
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Cache_WithETagAndNoCacheRequestDirective() do?
Test_Cache_WithETagAndNoCacheRequestDirective() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_Cache_WithETagAndNoCacheRequestDirective() defined?
Test_Cache_WithETagAndNoCacheRequestDirective() is defined in middleware/cache/cache_test.go at line 690.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free