Socket
Book a DemoInstallSign in
Socket

sustainyfacts.dev/anycache

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sustainyfacts.dev/anycache

Go Modules
Version
v0.3.0
Version published
Created
Source

AnyCache

🚧 Work in Progress

This library is a working in progress, and as a result even the public API will probably change

Simple Cache wrapper that allows selecting the cache implementation without changing your code.

It is inspired by Gocache and GroupCache

Requires Go 1.21 or newer.

Features

  • No external dependencies: all dependencies to 3rd party libraries are in the adapters provided, so you can choose what code you will deploy into your project.
  • Type-safe, loadable cache: uses a cacheLoader function to load your data into the cache. Because AnyCache is using generics, you can use your actual types instead of any.
  • Cache groups: several groups using a single underlying store for optimal performance and memory usage.
  • Configurable cache stores: in-memory, redis, or your own custom store.
  • 🚧 Second level store: back your in-memory store by a redis instance, so that you cache survives deployment of a new version of your application.
  • 🚧 Cache invalidation by expiration time
  • Distributed invalidation: inject a message broker to enable distributed invalidation of the in-memory caches in your cluster
  • 🚧 Prometheus metrics: provides metrics, for each group, globally, and for first and second level separately

Built-in adapters

Usage

Simple initialization

import (
	"fmt"

	"sustainyfacts.dev/anycache/cache"
)

func SimpleExample() {
	group := cache.NewFactory("TestRistretto",
		func(key string) (string, error) {
			return "value for " + key, nil
		}).Cache()

	v, _ := group.Get("my-unique-key")
	fmt.Println(v)
}

Benchmarks

Todo

License

AnyCache is released under the Apache 2.0 license (see LICENSE)

FAQs

Package last updated on 17 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts