memory.go — fiber Source File
Architecture documentation for memory.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5c209b8e_493c_b462_178d_8ab949ed52c2["memory.go"] 4a89612e_cb9d_437c_e107_9ce21cddffbe["sync"] 5c209b8e_493c_b462_178d_8ab949ed52c2 --> 4a89612e_cb9d_437c_e107_9ce21cddffbe style 5c209b8e_493c_b462_178d_8ab949ed52c2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
// Package memory provides a high-performance in-memory storage that can store
// any type without encoding overhead. Unlike the standard storage interface,
// this storage works directly with Go types for maximum speed.
//
// # Safety Considerations
//
// This storage automatically performs defensive copying for:
// - String keys: Copied to prevent corruption from pooled buffers
// - []byte values: Copied on both Set and Get to prevent external mutation
//
// For other types (structs, ints, etc.), Go's value semantics provide natural
// protection. However, if storing pointers or slices of non-byte types,
// callers are responsible for not mutating the underlying data.
//
// This storage is primarily used internally by middleware for performance-
// critical operations where the stored data types are known and controlled.
package memory
import (
"sync"
"time"
"github.com/gofiber/utils/v2"
)
// Storage stores arbitrary values in memory for use in tests and benchmarks.
type Storage struct {
data map[string]item // data
mu sync.RWMutex
}
type item struct {
v any // val
// max value is 4294967295 -> Sun Feb 07 2106 06:28:15 GMT+0000
e uint32 // exp
}
// New constructs an in-memory Storage initialized with a background GC loop.
func New() *Storage {
store := &Storage{
data: make(map[string]item),
}
utils.StartTimeStampUpdater()
go store.gc(1 * time.Second)
return store
}
// Get retrieves the value stored under key, returning nil when the entry does
// not exist or has expired.
//
// For []byte values, this returns a defensive copy to prevent callers from
// mutating the stored data. Other types are returned as-is.
func (s *Storage) Get(key string) any {
s.mu.RLock()
v, ok := s.data[key]
s.mu.RUnlock()
if !ok || v.e != 0 && v.e <= utils.Timestamp() {
return nil
}
// ... (83 more lines)
Domain
Subdomains
Functions
Dependencies
- sync
Source
Frequently Asked Questions
What does memory.go do?
memory.go is a source file in the fiber codebase, written in go. It belongs to the InternalStorage domain, MemoryStore subdomain.
What functions are defined in memory.go?
memory.go defines 1 function(s): New.
What does memory.go depend on?
memory.go imports 1 module(s): sync.
Where is memory.go in the architecture?
memory.go is located at internal/memory/memory.go (domain: InternalStorage, subdomain: MemoryStore, directory: internal/memory).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free