Documentation ¶
Overview ¶
Package cache implements the functions, types, and interfaces for the module.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrClosed error = &cacheError{msg: "cache closed"} ErrNotFound error = &cacheError{msg: "cache not found"} ErrInvalidElement error = &cacheError{msg: "invalid cache element"} ErrExpired error = &cacheError{msg: "cache expired"} )
Functions ¶
func NewErrorWith ¶
Types ¶
type Cache ¶
type Cache interface { // Get retrieves the value associated with the given key. // It returns the cached value and an error if the key is not found. Get(ctx context.Context, key string) (string, error) // GetAndDelete retrieves the value associated with the given key and deletes it. // It returns the cached value and an error if the key is not found. GetAndDelete(ctx context.Context, key string) (string, error) // Exists checks if a value exists for the given key. // It returns an error if the key is not found. Exists(ctx context.Context, key string) (bool, error) // Set sets the value for the given key. // It returns an error if the operation fails. Set(ctx context.Context, key string, value string, exp ...time.Duration) error // Delete deletes the value associated with the given key. // It returns an error if the operation fails. Delete(ctx context.Context, key string) error // Close closes the cache. Close(ctx context.Context) error // Clear clears the cache. Clear(ctx context.Context) error }
Cache is the interface that wraps the basic Get, Set, and Delete methods. It uses string as the value type, allowing for flexible conversion to []byte and zero-copy resource optimization after go1.22.
func NewMemoryCache ¶ added in v0.1.28
func NewMemoryCache() Cache
Click to show internal directories.
Click to hide internal directories.