cache

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cache handles caching and pub/sub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Rdb *redis.Client
	Ctx context.Context
	// contains filtered or unexported fields
}

Cache uses Redis to implement the Volatilizer interface

func NewCache

func NewCache(log *logger.Logger) *Cache

NewCache returns an initiated Redis client

func (*Cache) Dec

func (c *Cache) Dec(key string, by int64) (int64, error)

Dec decreases a value (atomic per Redis)

func (*Cache) DequeueWork

func (c *Cache) DequeueWork(key string) (string, error)

DequeueWork uses Redis's LIST (atomic) to get the next work queue value You'd typically call this from a time.Ticker for instance or in some kind of loop

func (*Cache) Get

func (c *Cache) Get(key string) (string, error)

Get gets a value by its id

func (*Cache) GetTyped

func (c *Cache) GetTyped(key string, v interface{}) error

GetTyped retrives the value for a key and unmarshal the JSON value into the interface

func (*Cache) HasPermission

func (c *Cache) HasPermission(token, repo, payload string) bool

HasPermission determines if a session token has permission to a collection

func (*Cache) Inc

func (c *Cache) Inc(key string, by int64) (int64, error)

Inc increments a value (atomic inc per Redis)

func (*Cache) Publish

func (c *Cache) Publish(msg model.Command) error

Publish sends a message and all subscribers will receive it if they're subscribed to that topic

func (*Cache) PublishDocument

func (c *Cache) PublishDocument(auth model.Auth, dbName, channel, typ string, v interface{})

PublishDocument publishes a database update message (created, updated, deleted) All subscribers will get notified

func (*Cache) QueueWork

func (c *Cache) QueueWork(key, value string) error

QueueWork uses Redis's LIST (atomic) as a work queue

func (*Cache) Set

func (c *Cache) Set(key string, value string) error

Set sets a value for a key

func (*Cache) SetTyped

func (c *Cache) SetTyped(key string, v interface{}) error

SetTyped converts the interface into JSON before storing its string value

func (*Cache) Subscribe

func (c *Cache) Subscribe(send chan model.Command, token, channel string, close chan bool)

Subscribe subscribes to a topic to receive messages on system/user events

type CacheDev added in v1.4.0

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

CacheDev used in local dev mode and is memory-based

func NewDevCache added in v1.4.0

func NewDevCache(log *logger.Logger) *CacheDev

NewDevCache returns a memory-based Volatilizer

func (*CacheDev) Dec added in v1.4.0

func (d *CacheDev) Dec(key string, by int64) (int64, error)

Dec decrements a value (non-atomic)

func (*CacheDev) DequeueWork added in v1.4.0

func (d *CacheDev) DequeueWork(key string) (val string, err error)

DequeueWork uses a string slice to replicate a work queue (non-atomic) You'd typically call this from a time.Ticker for instance or in some kind of loop

func (*CacheDev) Get added in v1.4.0

func (d *CacheDev) Get(key string) (val string, err error)

Get gets a value by its id

func (*CacheDev) GetTyped added in v1.4.0

func (d *CacheDev) GetTyped(key string, v any) error

GetTyped retrives the value for a key and unmarshal the JSON value into the

func (*CacheDev) HasPermission added in v1.4.0

func (d *CacheDev) HasPermission(token, repo, payload string) bool

HasPermission determines if a session token has permission to a collection

func (*CacheDev) Inc added in v1.4.0

func (d *CacheDev) Inc(key string, by int64) (n int64, err error)

Inc increments a value (non-atomic)

func (*CacheDev) Publish added in v1.4.0

func (d *CacheDev) Publish(msg model.Command) error

Publish sends a message and all subscribers will receive it if they're subscribed to that topic

func (*CacheDev) PublishDocument added in v1.4.0

func (d *CacheDev) PublishDocument(auth model.Auth, dbName, channel, typ string, v any)

PublishDocument publishes a database update message (created, updated, deleted) All subscribers will get notified

func (*CacheDev) QueueWork added in v1.4.0

func (d *CacheDev) QueueWork(key, value string) error

QueueWork uses a slice to replicate a work queue (non-atomic)

func (*CacheDev) Set added in v1.4.0

func (d *CacheDev) Set(key string, value string) error

Set sets a value for a key

func (*CacheDev) SetTyped added in v1.4.0

func (d *CacheDev) SetTyped(key string, v any) error

SetTyped converts the interface into JSON before storing its string value

func (*CacheDev) Subscribe added in v1.4.0

func (d *CacheDev) Subscribe(send chan model.Command, token, channel string, close chan bool)

Subscribe subscribes to a topic to receive messages on system/user events

type PublishDocumentEvent added in v1.4.1

type PublishDocumentEvent func(auth model.Auth, dbName, channel, typ string, v interface{})

PublishDocumentEvent used to publish database events

type Volatilizer added in v1.4.1

type Volatilizer interface {
	// Get returns a string value from a key
	Get(key string) (string, error)
	// Set sets a string value
	Set(key string, value string) error
	// GetTyped returns a typed struct by its key
	GetTyped(key string, v any) error
	// SetTyped sets a typed struct for a key
	SetTyped(key string, v any) error
	// Inc increments a numeric value for a key
	Inc(key string, by int64) (int64, error)
	// Dec decrements a value for a key
	Dec(key string, by int64) (int64, error)
	// Subscribe subscribes to a pub/sub channel
	Subscribe(send chan model.Command, token, channel string, close chan bool)
	// Publish publishes a message to a channel
	Publish(msg model.Command) error
	// PublishDocument publish a database message to a channel
	PublishDocument(auth model.Auth, dbname, channel, typ string, v any)
	// QueueWork add a work queue item
	QueueWork(key, value string) error
	// DequeueWork dequeue work item (if available)
	DequeueWork(key string) (string, error)
}

Volatilizer is the cache and pub/sub interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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