k6cache

package module
v0.0.0-...-b2e9cc0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

k6cache

A bunch of random functions for k6 performance testing that I found missing, but useful in our work.

Compile for development

xk6 build v0.45.0 \
  --with github.com/b4dc0d3rs/k6-cache=.

./k6 run k6caches.js

Use

Import this:

import k6cache from 'k6/x/k6cache'

Default expiring cache

Default cache has automatic expiry measured in seconds. There is one default cache that share the same expiry duration.

Usage examples:
// Configure it in the setup method
k6utils.createCacheWithExpiryInSeconds(1)

// Insert anything anytime
k6utils.putToCache('key', 'value')

// Get anywhere anytime, even in a different method
k6utils.getFromCache('key')

k6utils.removeFromCache('key')

Named caches

k6-cache stores a map of caches. Each cache can have different autoexpiry duration.

Use this when single expiry duration in the default cache is not enough.

To create a named cache with expiry in seconds:

k6cache.createWithExpiryInSeconds('cache_name', 1)

Named cache must be created before use. If not, an error will be thrown.

Methods that share this cache have Named in the name.

To put key-value to the named cache:

k6cache.putToNamedCache("cache_name", "key", "value")

The same pattern applies when inserting and deleting from a named cache:

k6cache.getFromNamedCache("cache_name", "key")

k6cache.removeFromNamedCache("cache_name", "key")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type K6Cache

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

func (*K6Cache) CreateCacheWithExpiryInSeconds

func (k6cache *K6Cache) CreateCacheWithExpiryInSeconds(durationInSeconds int)

func (*K6Cache) CreateWithExpiryInSeconds

func (k6cache *K6Cache) CreateWithExpiryInSeconds(name string, durationInSeconds int)

func (*K6Cache) GetFromCache

func (k6cache *K6Cache) GetFromCache(key string) interface{}

func (*K6Cache) GetFromNamedCache

func (k6cache *K6Cache) GetFromNamedCache(name string, key string) (interface{}, error)

func (*K6Cache) PutToCache

func (k6cache *K6Cache) PutToCache(key string, value string)

func (*K6Cache) PutToNamedCache

func (k6cache *K6Cache) PutToNamedCache(name string, key string, value string) error

func (*K6Cache) RemoveFromCache

func (k6cache *K6Cache) RemoveFromCache(key string)

func (*K6Cache) RemoveFromNamedCache

func (k6cache *K6Cache) RemoveFromNamedCache(name string, key string) error

Jump to

Keyboard shortcuts

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