timed

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrItemHasExpired = errors.New("item has expired")
)

Functions

This section is empty.

Types

type Cache

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

Cache represents an in-memory cache

func NewCache

func NewCache() *Cache

NewCache creates a new Cache instance

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a value from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves a value from the cache

func (*Cache) Has

func (c *Cache) Has(key string) bool

Has checks if the cache contains a key

func (*Cache) Set

func (c *Cache) Set(key string, item *Item) error

Set adds the item to the cache

func (*Cache) UpdateExpiresAt added in v0.1.1

func (c *Cache) UpdateExpiresAt(key string, expiresAt time.Time) error

UpdateExpiresAt updates the expiration time of an item in the cache

func (*Cache) UpdateValue added in v0.1.1

func (c *Cache) UpdateValue(key string, value interface{}) error

UpdateValue updates the value of an item in the cache

type Item

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

Item represents a cached value with an expiration time

func NewItem

func NewItem(value interface{}, expiresAt time.Time) *Item

NewItem creates a new cache item

func (*Item) GetExpiresAt added in v0.1.1

func (i *Item) GetExpiresAt() time.Time

GetExpiresAt returns the expiration time of the cached value

func (*Item) GetValue added in v0.1.1

func (i *Item) GetValue() interface{}

GetValue returns the cached value

func (*Item) HasExpired added in v0.1.1

func (i *Item) HasExpired() bool

HasExpired returns true if the cached value has expired

func (*Item) SetExpiresAt added in v0.1.1

func (i *Item) SetExpiresAt(expiresAt time.Time)

SetExpiresAt sets the expiration time of the cached value

func (*Item) SetValue added in v0.1.1

func (i *Item) SetValue(value interface{})

SetValue sets the cached value

Jump to

Keyboard shortcuts

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