Documentation
¶
Index ¶
Constants ¶
const ( // NoExpireDuration indicates that cache items should not expire. // Use this value to store items permanently in the cache. NoExpireDuration time.Duration = -1 )
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new localcache instance with optional configurations. It applies defaults if no options are provided and starts the cleanup goroutine if a cleanup interval is configured.
The cache is thread-safe and can be used concurrently from multiple goroutines. A background cleanup process will automatically remove expired items based on the configured cleanup interval.
Parameters:
- opts: Optional configuration functions
Returns:
- A new cache.Cache[T] instance
Example:
// Create cache with default settings cache := New[string]() // Create cache with custom expiration and cleanup interval cache := New[User]( WithDefaultExpiration(30 * time.Minute), WithCleanupInterval(5 * time.Minute), )
Types ¶
type Option ¶
type Option func(*config)
Option is a function type for configuring the local cache.
func WithCleanupInterval ¶
WithCleanupInterval sets the interval for automatically cleaning up expired items. A background goroutine will run periodically to remove expired items from memory.
func WithDefaultExpiration ¶
WithDefaultExpiration sets the default expiration duration for cache items. If not specified, items will not expire by default.