lambdacache

module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT

README

license Go Report Card Go Reference

lambdacache

lambdacache is a Go package for caching data in your AWS Lambda function between sequential invocations. It stores data in the memory of the function execution context that usually spans multiple consecutive invocations.

Usage


// 1. import the package
import "github.com/udhos/lambdacache/lambdacache"

// 2. in lambda function GLOBAL context: create cache
var cache = newCache()

func newCache() *lambdacache.Cache {
	options := lambdacache.Options{
		Debug:    true,
		Retrieve: getInfo,
	}
	return lambdacache.New(options)
}

// 3. in lambda function HANDLER context: query cache
func HandleRequest(ctx context.Context) error {
	// ...
    value, errGet := cache.Get(key)
    // ...
	return nil
}

// getInfo retrieves key value when there is a cache miss
func getInfo(key string) (interface{}, time.Duration, error) {
    const ttl = 5 * time.Minute // per-key TTL
	return "put-retrieved-value-here", ttl, nil
}

Example

See:

./cmd/lambdacache-example/main.go

Directories

Path Synopsis
cmd
lambdacache-example
Package main implements the example.
Package main implements the example.
Package lambdacache implements a cache for aws lambda go functions.
Package lambdacache implements a cache for aws lambda go functions.

Jump to

Keyboard shortcuts

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