Skip to content

streamdp/microcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microcache

Just a simple implementation of an in-memory cache with entry expiration

Usage

You can use it directly:

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/streamdp/microcache"
)

func main() {
	ctx := context.Background()
	cache := microcache.New(ctx, 0)
	_ = cache.Set(ctx, "key1", "val1", time.Hour)

	fmt.Println(cache.Get(ctx, "key1"))
}

Or create your own cache based on this solution, microCache implements the following interface:

type Cache interface {
    Get(ctx context.Context, key string) (any, error)
    Set(ctx context.Context, key string, value any, expiration time.Duration) error
    Delete(ctx context.Context, key string)
}

Look at the examples folder for explanations.

About

Just a simple implementation of an in-memory cache with entry expiration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages