cache

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache contains different byte-cache implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyKey means "empty key is used".
	ErrEmptyKey = errors.New("empty key")

	// ErrEmptyData means "no data provided".
	ErrEmptyData = errors.New("empty data")

	// ErrClosed means "cache was closed".
	ErrClosed = errors.New("cache closed")
)

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	// TTL returns current cache values time-to-live.
	TTL() time.Duration

	// Get value associated with the key from the storage.
	Get(key string) (found bool, data []byte, ttl time.Duration, err error)

	// Put value into the storage.
	Put(key string, data []byte) error

	// Delete value from the storage with passed key.
	Delete(key string) (bool, error)
}

Cacher is a byte-based cache with TTL.

type InMemoryCache

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

InMemoryCache is an inmemory cache (with TTL) implementation.

func NewInMemoryCache

func NewInMemoryCache(ttl time.Duration, ci time.Duration) *InMemoryCache

NewInMemoryCache creates inmemory storage with TTL.

func (*InMemoryCache) Close

func (c *InMemoryCache) Close() error

Close current in memory storage with data invalidation.

func (*InMemoryCache) Delete

func (c *InMemoryCache) Delete(key string) (bool, error)

Delete value from the storage with passed key.

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(key string) (bool, []byte, time.Duration, error)

Get value associated with the key from the storage.

func (*InMemoryCache) Put

func (c *InMemoryCache) Put(key string, data []byte) error

Put value into the storage.

func (*InMemoryCache) TTL

func (c *InMemoryCache) TTL() time.Duration

TTL returns current cache values time-to-live.

type RedisCache

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

RedisCache is a redis cache implementation.

func NewRedisCache

func NewRedisCache(ctx context.Context, client *redis.Client, ttl time.Duration) *RedisCache

NewRedisCache creates new redis cache instance.

func (*RedisCache) Delete

func (c *RedisCache) Delete(key string) (bool, error)

Delete value from the storage with passed key.

func (*RedisCache) Get

func (c *RedisCache) Get(key string) (found bool, data []byte, ttl time.Duration, err error)

Get retrieves value for the key from the storage.

func (*RedisCache) Put

func (c *RedisCache) Put(key string, data []byte) error

Put value into the storage.

func (*RedisCache) TTL

func (c *RedisCache) TTL() time.Duration

TTL returns current cache values time-to-live.

Jump to

Keyboard shortcuts

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