Home / Function/ Test_Cache_Expired() — fiber Function Reference

Test_Cache_Expired() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 526–562

func Test_Cache_Expired(t *testing.T) {
	t.Parallel()
	app := fiber.New()
	app.Use(New(Config{Expiration: 2 * time.Second}))
	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)

	// Sleep until the cache is expired
	time.Sleep(3 * time.Second)

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

	if bytes.Equal(body, bodyCached) {
		t.Errorf("Cache should have expired: %s, %s", body, bodyCached)
	}

	// Next response should be also cached
	respCachedNextRound, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	bodyCachedNextRound, err := io.ReadAll(respCachedNextRound.Body)
	require.NoError(t, err)

	if !bytes.Equal(bodyCachedNextRound, bodyCached) {
		t.Errorf("Cache should not have expired: %s, %s", bodyCached, bodyCachedNextRound)
	}
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free