Home / Function/ Test_CacheInvalidation() — fiber Function Reference

Test_CacheInvalidation() — fiber Function Reference

Architecture documentation for the Test_CacheInvalidation() function in cache_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  48569a85_ab34_4cb6_895a_07769397ef9c["Test_CacheInvalidation()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  48569a85_ab34_4cb6_895a_07769397ef9c -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  style 48569a85_ab34_4cb6_895a_07769397ef9c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 1275–1308

func Test_CacheInvalidation(t *testing.T) {
	t.Parallel()

	app := fiber.New()
	app.Use(New(Config{
		CacheInvalidator: func(c fiber.Ctx) bool {
			return fiber.Query[bool](c, "invalidate")
		},
	}))

	count := 0
	app.Get("/", func(c fiber.Ctx) error {
		count++
		return c.SendString(strconv.Itoa(count))
	})

	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	body, err := io.ReadAll(resp.Body)
	require.NoError(t, err)

	respCached, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	bodyCached, err := io.ReadAll(respCached.Body)
	require.NoError(t, err)
	require.True(t, bytes.Equal(body, bodyCached))
	require.NotEmpty(t, respCached.Header.Get(fiber.HeaderCacheControl))

	respInvalidate, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/?invalidate=true", http.NoBody))
	require.NoError(t, err)
	bodyInvalidate, err := io.ReadAll(respInvalidate.Body)
	require.NoError(t, err)
	require.NotEqual(t, body, bodyInvalidate)
}

Subdomains

Frequently Asked Questions

What does Test_CacheInvalidation() do?
Test_CacheInvalidation() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_CacheInvalidation() defined?
Test_CacheInvalidation() is defined in middleware/cache/cache_test.go at line 1275.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free