Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Contents() string
- func (c *Cache) Count() int
- func (c *Cache) Delete(key string)
- func (c *Cache) Exists(key string) bool
- func (c *Cache) Get(key string) (any, bool)
- func (c *Cache) Keys() []string
- func (c *Cache) Set(key string, value any)
- func (c *Cache) Values() []any
- type CacheEntry
- type CacheOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps the go-cache library to provide an in-memory key-value store.
func New ¶
func New(opts ...CacheOption) *Cache
New constructs a new in-memory cache instance with optional configurations. By default, it sets the expiration and purge intervals to 12 and 13 hours, respectively. These defaults can be overridden using the functional options: WithExpirationInterval and WithPurgeInterval.
func NewWithData ¶
func NewWithData(data []CacheEntry, opts ...CacheOption) *Cache
NewWithData constructs a new in-memory cache with existing data. It also accepts CacheOption parameters to override default configuration values.
func (*Cache) Contents ¶
Contents returns a comma-separated string containing all keys in the cache.
type CacheEntry ¶ added in v3.63.9
type CacheEntry struct { // Key is the unique identifier for the entry. Key string // Value is the data stored in the entry. Value any }
CacheEntry represents a single entry in the cache, consisting of a key and its corresponding value.
type CacheOption ¶ added in v3.63.9
type CacheOption func(*Cache)
CacheOption defines a function type used for configuring a Cache.
func WithExpirationInterval ¶ added in v3.63.9
func WithExpirationInterval(interval time.Duration) CacheOption
WithExpirationInterval returns a CacheOption to set the expiration interval of cache items. The interval determines the duration a cached item remains in the cache before it is expired.
func WithPurgeInterval ¶ added in v3.63.9
func WithPurgeInterval(interval time.Duration) CacheOption
WithPurgeInterval returns a CacheOption to set the interval at which the cache purges expired items. Regular purging helps in freeing up memory by removing stale entries.