redcache

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Overview

Package redcache provides a simple cache implementation using Redis as a backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[V any] struct {
	TTL    time.Duration
	Client *redjet.Client
	// Prefix is the prefix used for all keys in the cache.
	Prefix string
}

Cache is a simple cache implementation using Redis as a backend.

func (*Cache[V]) Do

func (c *Cache[V]) Do(
	ctx context.Context,
	key string,
	fn func() (V, error),
) (V, error)

Do executes fn and caches the result for key. If the value is already cached, it is returned immediately.

Do uses JSON to marshal and unmarshal values. It may not perform well for large values.

Jump to

Keyboard shortcuts

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