cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides in-memory caching with a built-in captcha store.

The local cache is backed by gkit's local_cache and supports TTL-based expiration. The Base64CaptchaStore implements the captcha store interface for verification code storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Local

func Local() local_cache.Cache

func Redis

func Redis(driver ...string) *redis.Client

func RedisDel

func RedisDel(key string)

func RedisHOQ

func RedisHOQ[T any](key string, queryFunc func() (data T, exp time.Duration, err error)) (T, error)

RedisHOQ is a generic function that attempts to retrieve data from Redis cache using the provided key. If the data is not found in the cache, it executes the provided query function to fetch the data, caches it, and returns it. It uses singleflight to ensure that only one query is executed for a given key at a time.

func RedisHOQGob

func RedisHOQGob[T any](key string, queryFunc func() (T, time.Duration, error)) (T, error)

func RedisHasOrQuery deprecated

func RedisHasOrQuery(key string, queryFunc func() (data string, exp time.Duration)) string

Deprecated: Use RedisHOQ() instead.

func RedisHasOrQueryByte

func RedisHasOrQueryByte(key string, queryFunc func() (data []byte, exp time.Duration)) []byte

func RedisHasOrQuerySerializerGob deprecated

func RedisHasOrQuerySerializerGob[T any](key string, resultReceiver *T, queryFunc func(*T) (expirationTime time.Duration, err error)) error

Deprecated: Use RedisHOQGob() instead.

func RedisStrGet

func RedisStrGet(key string) string

func RedisStrSet

func RedisStrSet(key, value string, exp time.Duration)

Types

type Base64CaptchaStore

type Base64CaptchaStore struct {
}

TODO 验证码使用本地缓存,在多机部署时会存在问题

func (Base64CaptchaStore) Get

func (b Base64CaptchaStore) Get(id string, clear bool) string

func (Base64CaptchaStore) Set

func (b Base64CaptchaStore) Set(id string, value string) error

func (Base64CaptchaStore) Verify

func (b Base64CaptchaStore) Verify(id string, answer string, clear bool) bool

Jump to

Keyboard shortcuts

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