cache

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 5 Imported by: 2 modules, 2 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

Index

Constants

View Source
const DefaultExpiration time.Duration = 0

Variables

This section is empty.

Functions

func GetOrFetch added in v0.0.9

func GetOrFetch(c Cache, key string, fx func() (interface{}, time.Duration, error), fv func(v interface{}) (interface{}, error)) (interface{}, error)

Types

type Cache added in v0.0.5

type Cache interface {
	Set(key string, value interface{}, expiration time.Duration) error
	SetDefault(key string, value interface{}) error
	Get(key string) (interface{}, bool, error)
	GetExpiration(key string) (time.Time, error)
	GetOrFetch(key string, fx func() (interface{}, time.Duration, error), fv func(v interface{}) (interface{}, error)) (interface{}, error)
	Delete(keys ...string) error
	Size() int
	Flush()
}

type MemoryCache

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

func NewMemoryCache

func NewMemoryCache(defaultExpiration time.Duration, items map[string]MemoryCacheItem) *MemoryCache

func NewMemoryCacheWithCleaner

func NewMemoryCacheWithCleaner(defaultExpiration, cleanInterval time.Duration, items map[string]MemoryCacheItem) *MemoryCache

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(keys ...string) error

func (*MemoryCache) DeleteExpired

func (c *MemoryCache) DeleteExpired()

func (*MemoryCache) Flush

func (c *MemoryCache) Flush()

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (interface{}, bool, error)

func (*MemoryCache) GetExpiration

func (c *MemoryCache) GetExpiration(key string) (time.Time, error)

func (*MemoryCache) GetOrFetch added in v0.0.9

func (c *MemoryCache) GetOrFetch(key string, fx func() (interface{}, time.Duration, error), fv func(v interface{}) (interface{}, error)) (interface{}, error)

func (*MemoryCache) Items

func (c *MemoryCache) Items() map[string]interface{}

func (*MemoryCache) Set

func (c *MemoryCache) Set(key string, value interface{}, expiration time.Duration) error

func (*MemoryCache) SetDefault

func (c *MemoryCache) SetDefault(key string, value interface{}) error

func (*MemoryCache) Size

func (c *MemoryCache) Size() int

type MemoryCacheItem

type MemoryCacheItem struct {
	Object     interface{}
	Expiration int64
}

func (MemoryCacheItem) Expired

func (item MemoryCacheItem) Expired() bool

type RedisCache added in v0.0.5

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

func NewRedisCache added in v0.0.5

func NewRedisCache(defaultExpiration time.Duration, cli *rdx.Client) *RedisCache

func (*RedisCache) Delete added in v0.0.5

func (c *RedisCache) Delete(keys ...string) error

func (*RedisCache) Flush added in v0.0.5

func (c *RedisCache) Flush()

func (*RedisCache) Get added in v0.0.5

func (c *RedisCache) Get(key string) (interface{}, bool, error)

func (*RedisCache) GetExpiration added in v0.0.5

func (c *RedisCache) GetExpiration(key string) (time.Time, error)

func (*RedisCache) GetOrFetch added in v0.0.9

func (c *RedisCache) GetOrFetch(key string, fx func() (interface{}, time.Duration, error), fv func(v interface{}) (interface{}, error)) (interface{}, error)

func (*RedisCache) Set added in v0.0.5

func (c *RedisCache) Set(key string, value interface{}, expiration time.Duration) error

func (*RedisCache) SetDefault added in v0.0.5

func (c *RedisCache) SetDefault(key string, value interface{}) error

func (*RedisCache) Size added in v0.0.5

func (c *RedisCache) Size() int

Jump to

Keyboard shortcuts

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