cache

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// GetLocal returns the object in local cache, if it exists.
	// Returns true if found, false if not found
	Get(ctx context.Context, id string, out interface{}) bool

	// Set both remote and local caches
	Set(ctx context.Context, element Cacheable) error

	// SetRaw lets you choose the id instead of relying on the Cacheable interface
	SetRaw(ctx context.Context, id string, element interface{}) error

	// Drop both remote and local cache entry
	Drop(ctx context.Context, ids ...string) error

	// Flush removes all entries in remote and local cache
	Flush(ctx context.Context) error
}

Cache unifies cache usage across the project.

func NewKV

func NewKV() Cache

NewKV is a local Key: Value storage using a stock golang map[string]interface{}. Very useful for tests but could be used for any local cache.

func NewThreadSafeCache

func NewThreadSafeCache(c Cache) Cache

NewThreadSafeCache creates the wrapped cache

type Cacheable

type Cacheable interface {
	CacheID() string
}

Cacheable makes your struct cache-able

type KVCache

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

KVCache is a simple map[string]interface{} so you get a very simple local key:value storage.

func (*KVCache) Drop

func (c *KVCache) Drop(ctx context.Context, ids ...string) error

Drop ...

func (*KVCache) Flush

func (c *KVCache) Flush(ctx context.Context) error

Flush ...

func (*KVCache) Get

func (c *KVCache) Get(ctx context.Context, id string, out interface{}) bool

Get ...

func (*KVCache) Reset

func (c *KVCache) Reset()

Reset allocates a new cache map. Useful for tests.

func (*KVCache) Set

func (c *KVCache) Set(ctx context.Context, element Cacheable) error

Set ...

func (*KVCache) SetRaw

func (c *KVCache) SetRaw(ctx context.Context, id string, element interface{}) error

SetRaw ...

func (*KVCache) Store

func (c *KVCache) Store() map[string]interface{}

Store returns the underlying cache map. Useful for tests.

type ThreadSafeCache

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

ThreadSafeCache wrap Cache with locks

func (*ThreadSafeCache) Drop

func (tsc *ThreadSafeCache) Drop(ctx context.Context, ids ...string) error

Drop ...

func (*ThreadSafeCache) Flush

func (tsc *ThreadSafeCache) Flush(ctx context.Context) error

Flush ...

func (*ThreadSafeCache) Get

func (tsc *ThreadSafeCache) Get(ctx context.Context, id string, out interface{}) bool

Get ...

func (*ThreadSafeCache) Set

func (tsc *ThreadSafeCache) Set(ctx context.Context, element Cacheable) error

Set ...

func (*ThreadSafeCache) SetRaw

func (tsc *ThreadSafeCache) SetRaw(ctx context.Context, id string, element interface{}) error

SetRaw ...

Jump to

Keyboard shortcuts

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