memorycache

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheOption

type CacheOption map[string]interface{}

type CacheValue

type CacheValue struct {
	// The cache's expiration time
	ExpirationTime time.Time
	// The cache's value
	Value string
}

type KvCache

type KvCache struct {
	// contains filtered or unexported fields
}

func NewKvCache

func NewKvCache(opts ...CacheOption) *KvCache

NewKvCache instantiates a new Cache and sets the default values. The default expiration time is set to 6 hours from the current time. The expiration time can be overridden by passing an expirationTime option. Example: cache := NewKvCache(ExpirationTime: time.Now().Add(1 * time.Hour))

func (*KvCache) Add

func (c *KvCache) Add(key string, value string)

Add adds a new key-value pair to the cache. If the key already exists, it will be overwritten.

func (*KvCache) Get

func (c *KvCache) Get(key string) (string, bool)

Get retrieves a value from the cache. If the key does not exist or the value has expired, it will return false.

func (*KvCache) Remove

func (c *KvCache) Remove(key string)

Remove removes a key-value pair from the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL