Documentation
¶
Overview ¶
Package cache provides a set of caching utilities for Go applications.
Index ¶
Constants ¶
View Source
const DefaultDelimiter = ":"
DefaultDelimiter is the default delimiter used in cache keys.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache[T any] interface { // Get retrieves the value associated with the given key. Get(ctx context.Context, key string) (T, error) // GetAndDelete retrieves the value associated with the given key and deletes it. GetAndDelete(ctx context.Context, key string) (T, error) // Exists checks if a value exists for the given key. Exists(ctx context.Context, key string) error // Set sets the value for the given key. Set(ctx context.Context, key string, value T, expiration ...time.Duration) error // Delete deletes the value associated with the given key. Delete(ctx context.Context, key string) error // Iterator iterates over all key-value pairs in the cache. Iterator(ctx context.Context, fn func(ctx context.Context, key string, value T) bool) error // Close releases any resources associated with the cache. Close(ctx context.Context) error }
Cache is the interface that wraps the basic Get, Set, and Delete methods.
type NSCache ¶
type NSCache[T any] interface { // Get retrieves the value associated with the given key in the specified namespace. Get(ctx context.Context, ns, key string) (T, error) // GetAndDelete retrieves the value associated with the given key in the specified namespace and deletes it. GetAndDelete(ctx context.Context, ns, key string) (T, error) // Exists checks if a value exists for the given key in the specified namespace. Exists(ctx context.Context, ns, key string) error // Set sets the value for the given key in the specified namespace. Set(ctx context.Context, ns, key string, value T, expiration ...time.Duration) error // Delete deletes the value associated with the given key in the specified namespace. Delete(ctx context.Context, ns, key string) error // Iterator iterates over all key-value pairs in the specified namespace. Iterator(ctx context.Context, ns string, fn func(ctx context.Context, key string, value T) bool) error // Close releases any resources associated with the cache. Close(ctx context.Context) error }
NSCache is the interface that wraps the basic Get, Set, and Delete methods for namespaced values.
type ObjectCache ¶
type ObjectCache interface {
// Get retrieves the value associated with the given key.
Get(ctx context.Context, key string) (any, error)
// GetAndDelete retrieves the value associated with the given key and deletes it.
GetAndDelete(ctx context.Context, key string) (any, error)
// Exists checks if a value exists for the given key.
Exists(ctx context.Context, key string) error
// Set sets the value for the given key.
Set(ctx context.Context, key string, value any, expiration ...time.Duration) error
// Delete deletes the value associated with the given key.
Delete(ctx context.Context, key string) error
// Iterator iterates over all key-value pairs in the cache.
Iterator(ctx context.Context, fn func(ctx context.Context, key string, value any) bool) error
// Close releases any resources associated with the cache.
Close(ctx context.Context) error
}
ObjectCache is the interface that wraps the basic Get, Set, and Delete methods for object values.
type ObjectNSCache ¶
type ObjectNSCache interface {
// Get retrieves the value associated with the given key in the specified namespace.
Get(ctx context.Context, ns, key string) (any, error)
// GetAndDelete retrieves the value associated with the given key in the specified namespace and deletes it.
GetAndDelete(ctx context.Context, ns, key string) (any, error)
// Exists checks if a value exists for the given key in the specified namespace.
Exists(ctx context.Context, ns, key string) error
// Set sets the value for the given key in the specified namespace.
Set(ctx context.Context, ns, key string, value any, expiration ...time.Duration) error
// Delete deletes the value associated with the given key in the specified namespace.
Delete(ctx context.Context, ns, key string) error
// Iterator iterates over all key-value pairs in the specified namespace.
Iterator(ctx context.Context, ns string, fn func(ctx context.Context, key string, value any) bool) error
// Close releases any resources associated with the cache.
Close(ctx context.Context) error
}
ObjectNSCache is the interface that wraps the basic Get, Set, and Delete methods for namespaced object values.
Click to show internal directories.
Click to hide internal directories.