memory

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ImportPath = "k6/x/working-memory"

Variables

This section is empty.

Functions

func New

func New() modules.Module

New creates and returns a new instance of rootModule, implementing the k6 modules.Module interface.

Types

type Cache

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

Cache struct encapsulates an in-memory cache with a mutex for concurrent access management.

func (*Cache) Flush

func (c *Cache) Flush() error

Flush clears all items from the cache, effectively resetting it.

func (*Cache) Get

func (c *Cache) Get(id string) (interface{}, error)

Get retrieves a value from the cache by its id. Parameters: - id: Unique identifier of the cache entry. Returns: - The cached value if found, or nil if the entry does not exist. - An error if the cache is not initialized or another issue occurs.

func (*Cache) Init

func (c *Cache) Init(defaultExpiration, cleanupInterval int)

Init initializes the Cache with a default expiration time and cleanup interval. Parameters: - defaultExpiration: Cache expiration time in seconds. - cleanupInterval: Interval in seconds at which expired items are removed from the cache.

func (*Cache) Set

func (c *Cache) Set(id, value string, expiration ...int) (bool, error)

Set stores a value in the cache under the specified id with an optional expiration. Parameters: - id: Unique identifier for the cache entry. - value: Value to store in the cache. - expiration: Optional expiration time in seconds. Defaults to the cache's default expiration if omitted. Returns: - A boolean indicating if the value was successfully set. - An error if the cache is not initialized or another issue occurs.

Jump to

Keyboard shortcuts

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