mirror of
https://github.com/gofiber/storage.git
synced 2025-10-10 11:00:25 +08:00
Memory
An in-memory storage driver.
Table of Contents
Signatures
func New(config ...Config) Storage
var ErrNotExist = errors.New("key does not exist")
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Clear() error
Examples
Import the storage package.
import "github.com/gofiber/storage/memory"
You can use the following possibilities to create a storage:
// Initialize default config
store := memory.New()
// Initialize custom config
store := memory.New(memory.Config{
GCInterval: 10 * time.Second,
})
Config
type Config struct {
// Time before deleting expired keys
//
// Default is 10 * time.Second
GCInterval time.Duration
}
Default Config
var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}