cache

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 6 Imported by: 4

README

dp-cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	UpdateFuncs map[string]func() (interface{}, error)
	// contains filtered or unexported fields
}

Cache contains all the information to start, update and close caching data

func NewCache

func NewCache(ctx context.Context, config Config) (*Cache, error)

NewCache create a cache object which will update at every updateInterval If updateInterval is nil, this means that the cache will only be updated once at the start of a service

func (*Cache) AddUpdateFunc

func (dc *Cache) AddUpdateFunc(key string, updateFunc func() (interface{}, error))

AddUpdateFunc adds an update function to the cache for a specific data corresponding to the `key` passed to the function This update function will then be triggered once or at every fixed interval as per the prior setup of the TopicCache

func (*Cache) Close

func (dc *Cache) Close()

Close closes the caching of data when called where the data will no longer be updated and the data itself is reset

func (*Cache) Get

func (dc *Cache) Get(key string) (interface{}, bool)

Get retrieves the specific value for the specified key stored in `data` within the `Cache`

func (*Cache) Set

func (dc *Cache) Set(key string, data interface{})

Set adds the specified value with the specified key in `data` within the `Cache`

func (*Cache) StartUpdates

func (dc *Cache) StartUpdates(ctx context.Context, errorChannel chan error)

StartUpdates informs the cache to start updating the cache data once called and then at every update interval which was configured when setting up the cache

func (*Cache) UpdateContent

func (dc *Cache) UpdateContent(ctx context.Context) error

UpdateContent calls all the update functions with a key value stored in the Cache to update the relevant data with the same key values

type Cacher

type Cacher interface {
	Close()
	Get(key string) (interface{}, bool)
	Set(key string, data interface{})
	AddUpdateFunc(key string, updateFunc func() (interface{}, error))
	StartUpdates(ctx context.Context, channel chan error)
}

Cacher defines the required methods to initialise a cache

type Config

type Config struct {
	UpdateInterval *time.Duration
}

Configs contains all the configurations for the cache

Jump to

Keyboard shortcuts

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