cache

package
v1.41.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache (memcache.go) provides a caching abstraction layer that can work with different backends (in-memory, Redis, etc.) to replace appengine/memcache.

Index

Constants

This section is empty.

Variables

View Source
var Gob = &gobCodec{}

Gob provides Gob codec for cache operations (compatible with memcache.Gob) For simplicity, we use JSON internally

View Source
var JSON = &jsonCodec{}

JSON provides JSON codec for cache operations (compatible with memcache.JSON)

Functions

func IncrementExisting

func IncrementExisting(ctx context.Context, key string, delta int64) (int64, error)

IncrementExisting increments an existing counter in the default cache

func MemDelete

func MemDelete(ctx context.Context, key string) error

MemDelete removes an item from the default cache

func MemGet

func MemGet(ctx context.Context, key string, dst interface{}) error

MemGet retrieves an item from the default cache

func MemSet

func MemSet(ctx context.Context, item *Item) error

MemSet stores an item in the default cache

func Set

func Set(ctx context.Context, item *Item) error

Set stores an item in the default cache (memcache-compatible API)

Types

type CacheError

type CacheError string

Error types

const (
	ErrCacheMiss CacheError = "cache: miss"
)

func (CacheError) Error

func (e CacheError) Error() string

type Item

type Item struct {
	Key        string
	Value      []byte
	Object     interface{}
	Expiration time.Duration
}

Item represents a cache item

func Get

func Get(ctx context.Context, key string) (*Item, error)

Get retrieves an item from the default cache (memcache-compatible API)

type Memoized

type Memoized func(args ...interface{}) interface{}

func Memoize

func Memoize(fn interface{}, args ...interface{}) Memoized

Cache result of fn, optionally expiring result.

func Once

func Once(fn interface{}) Memoized

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache is an in-memory cache implementation

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new in-memory cache

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(ctx context.Context, key string) error

Delete removes an item from the cache

func (*MemoryCache) Get

func (c *MemoryCache) Get(ctx context.Context, key string, dst interface{}) error

Get retrieves an item from the cache

func (*MemoryCache) IncrementExisting

func (c *MemoryCache) IncrementExisting(ctx context.Context, key string, delta int64) (int64, error)

IncrementExisting increments an existing counter

func (*MemoryCache) Set

func (c *MemoryCache) Set(ctx context.Context, item *Item) error

Set stores an item in the cache

Jump to

Keyboard shortcuts

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