Home / File/ cache.go — fiber Source File

cache.go — fiber Source File

Architecture documentation for cache.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberMiddleware Caching 1 imports 27 functions 16 classes

Entity Profile

Dependency Diagram

graph LR
  af95e058_7e86_ec88_42f0_cd294e342508["cache.go"]
  cc7104af_aece_1fe5_3985_791c7f34910c["context"]
  af95e058_7e86_ec88_42f0_cd294e342508 --> cc7104af_aece_1fe5_3985_791c7f34910c
  style af95e058_7e86_ec88_42f0_cd294e342508 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Special thanks to @codemicro for moving this to fiber core
// Original middleware: github.com/codemicro/fiber-cache
package cache

import (
	"context"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"fmt"
	"math"
	"slices"
	"sort"
	"strings"
	"sync"
	"sync/atomic"
	"time"

	"github.com/gofiber/utils/v2"
	"github.com/valyala/fasthttp"

	"github.com/gofiber/fiber/v3"
)

// timestampUpdatePeriod is the period which is used to check the cache expiration.
// It should not be too long to provide more or less acceptable expiration error, and in the same
// time it should not be too short to avoid overwhelming of the system
const timestampUpdatePeriod = 300 * time.Millisecond

// buffer size for hexpool
const hexLen = sha256.Size * 2

// cache status
// unreachable: when cache is bypass, or invalid
// hit: cache is served
// miss: do not have cache record
const (
	cacheUnreachable = "unreachable"
	cacheHit         = "hit"
	cacheMiss        = "miss"
)

type expirationSource uint8

const (
	expirationSourceConfig expirationSource = iota
	expirationSourceMaxAge
	expirationSourceSMaxAge
	expirationSourceExpires
	expirationSourceGenerator
)

// directives
const (
	noCache          = "no-cache"
	noStore          = "no-store"
	privateDirective = "private"
)

type requestCacheDirectives struct {
// ... (1323 more lines)

Subdomains

Dependencies

  • context

Frequently Asked Questions

What does cache.go do?
cache.go is a source file in the fiber codebase, written in go. It belongs to the FiberMiddleware domain, Caching subdomain.
What functions are defined in cache.go?
cache.go defines 27 function(s): New, allowsSharedCache, allowsSharedCacheDirectives, appendWarningHeaders, cacheBodyFetchError, cachedResponseAge, clampDateSeconds, hasDirective, isHeuristicFreshness, loadVaryManifest, and 17 more.
What does cache.go depend on?
cache.go imports 1 module(s): context.
Where is cache.go in the architecture?
cache.go is located at middleware/cache/cache.go (domain: FiberMiddleware, subdomain: Caching, directory: middleware/cache).

Analyze Your Own Codebase

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

Try Supermodel Free