caching

package
v0.0.0-...-e1d3906 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheMiddleware

type CacheMiddleware interface {

	// SetDatabase sets the passed database module
	// as cache storage fallback.
	SetDatabase(db database.Middleware)

	// GetUserByID returns a User object by ID
	GetUserByID(id snowflake.ID) (*objects.User, error)
	// SetUserByID sets a User object to the passed ID
	SetUserByID(id snowflake.ID, user *objects.User) error
	// GetUserByToken returns a User object by token string
	GetUserByToken(token string) (*objects.User, bool)
	// SetUserByToken sets a User object to the passed
	// token string
	SetUserByToken(token string, user *objects.User) error

	// GetPageByID returns a Page object by ID
	GetPageByID(id snowflake.ID) (*objects.Page, error)
	// SetPageByID sets a Page object to the passed ID
	SetPageByID(id snowflake.ID, page *objects.Page) error
}

CacheMiddleware describes a caching module providing functionality to store and fetch data to/from a cache storage. This module will be initialized with SetDatabase. The set database must be used to fetch data from when a value is not found in cache. This value must then be saved in the cache storage.

type Internal

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

Internal provides a caching module which uses a timedmap.TimedMap instance to store and manage cache values.

func NewInternal

func NewInternal() *Internal

NewInternal creates a new instance of Internal.

func (*Internal) GetPageByID

func (c *Internal) GetPageByID(id snowflake.ID) (*objects.Page, error)

func (*Internal) GetUserByID

func (c *Internal) GetUserByID(id snowflake.ID) (*objects.User, error)

func (*Internal) GetUserByToken

func (c *Internal) GetUserByToken(token string) (*objects.User, bool)

func (*Internal) SetDatabase

func (c *Internal) SetDatabase(db database.Middleware)

func (*Internal) SetPageByID

func (c *Internal) SetPageByID(id snowflake.ID, page *objects.Page) error

func (*Internal) SetUserByID

func (c *Internal) SetUserByID(id snowflake.ID, user *objects.User) error

func (*Internal) SetUserByToken

func (c *Internal) SetUserByToken(token string, user *objects.User) error

type Redis

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

Redis provides a caching module which uses Redis to store and manage cache values.

func NewRedis

func NewRedis(cfg *RedisConfig) *Redis

NewRedis creates a new instance of Redis with the given RedisConfig instance cfg.

func (*Redis) GetPageByID

func (c *Redis) GetPageByID(id snowflake.ID) (*objects.Page, error)

func (*Redis) GetUserByID

func (c *Redis) GetUserByID(id snowflake.ID) (*objects.User, error)

func (*Redis) GetUserByToken

func (c *Redis) GetUserByToken(token string) (*objects.User, bool)

func (*Redis) SetDatabase

func (c *Redis) SetDatabase(db database.Middleware)

func (*Redis) SetPageByID

func (c *Redis) SetPageByID(id snowflake.ID, page *objects.Page) error

func (*Redis) SetUserByID

func (c *Redis) SetUserByID(id snowflake.ID, user *objects.User) error

func (*Redis) SetUserByToken

func (c *Redis) SetUserByToken(token string, user *objects.User) error

type RedisConfig

type RedisConfig struct {
	Enabled bool `json:"enabled"`

	Addr     string `json:"addr"`
	Password string `json:"password"`
	DB       int    `json:"db"`
}

RedisConfig contains configuration values for the Redis Database connection.

Jump to

Keyboard shortcuts

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