Home / Function/ Test_CacheInvalidExpiresStoredAsStale() — fiber Function Reference

Test_CacheInvalidExpiresStoredAsStale() — fiber Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  57d80c8e_ebdc_62dc_6a3a_212c514b27aa["Test_CacheInvalidExpiresStoredAsStale()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  57d80c8e_ebdc_62dc_6a3a_212c514b27aa -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  764bea14_4c8a_81bd_ccd6_a1952b5d95d1["newFailingCacheStorage()"]
  57d80c8e_ebdc_62dc_6a3a_212c514b27aa -->|calls| 764bea14_4c8a_81bd_ccd6_a1952b5d95d1
  style 57d80c8e_ebdc_62dc_6a3a_212c514b27aa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 1771–1821

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

	storage := newFailingCacheStorage()

	app := fiber.New()
	app.Use(New(Config{
		Expiration: 30 * time.Second,
		KeyGenerator: func(c fiber.Ctx) string {
			return c.Path() + "|invalid-expires"
		},
		Storage: storage,
	}))

	var count int
	app.Get("/", func(c fiber.Ctx) error {
		count++
		c.Set(fiber.HeaderCacheControl, "public")
		c.Set(fiber.HeaderExpires, "invalid-date")
		return c.SendString("body" + strconv.Itoa(count))
	})

	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
	body, err := io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "body1", string(body))

	expectedKey := "/|invalid-expires_GET"
	require.Contains(t, storage.data, expectedKey)
	require.Contains(t, storage.data, expectedKey+"_body")

	resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
	body, err = io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "body2", string(body))
	require.Contains(t, storage.data, expectedKey)
	require.Contains(t, storage.data, expectedKey+"_body")

	resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
	body, err = io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "body3", string(body))
	require.Contains(t, storage.data, expectedKey)
	require.Contains(t, storage.data, expectedKey+"_body")
}

Subdomains

Frequently Asked Questions

What does Test_CacheInvalidExpiresStoredAsStale() do?
Test_CacheInvalidExpiresStoredAsStale() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_CacheInvalidExpiresStoredAsStale() defined?
Test_CacheInvalidExpiresStoredAsStale() is defined in middleware/cache/cache_test.go at line 1771.
What does Test_CacheInvalidExpiresStoredAsStale() call?
Test_CacheInvalidExpiresStoredAsStale() calls 1 function(s): newFailingCacheStorage.

Analyze Your Own Codebase

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

Try Supermodel Free