Skip to content

limpo1989/gcache

Repository files navigation

GCache

GoDoc

Cache library for golang. It supports expirable Cache, LFU, LRU and ARC.

Features

  • Supports expirable Cache, LFU, LRU and ARC.
  • Auto-renewal cache items. (Optional)
  • Goroutine safe.
  • Supports event handlers which evict, purge, and add entry. (Optional)
  • Automatically load cache if it doesn't exists. (Optional)
  • Supports context.
  • Supports shared cache.
  • Supports generic interface.
  • Supports managed by the Arena allocator. (Optional)

Install

$ go get github.com/limpo1989/gcache

Example

package main

import (
	"context"
	"fmt"

	"github.com/limpo1989/gcache"
)

func main() {
	gc := gcache.New[string, string](20).
		LRU().
		LoaderFunc(func(ctx context.Context, key string) (*string, error) {
			value := "ok"
			return &value, nil
		}).
		Build()
	value, err := gc.Get(context.Background(), "key")
	if err != nil {
		panic(err)
	}
	fmt.Println("Get:", *value)
}

Acknowledgement

This project initial code based from gcache written by bluele

About

Cache library for golang. It supports expirable Cache, LFU, LRU and ARC.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages