xormcache

package module
v0.0.0-...-51c89d6 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: MIT Imports: 12 Imported by: 1

README

xormcache

xorm.io is a database xorm library for golang. The xorm.io library provides an interface to implement the cache and already provides a localized lru cache. But localized caches are not suitable for microservices, because there may be multiple different services in microservices that use the database so they need a common network cache.

I wanted to use redis as a network cache for xorm.io, so I wrote this library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryCoder

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

func NewBinaryCoder

func NewBinaryCoder() *BinaryCoder

func (*BinaryCoder) Decode

func (c *BinaryCoder) Decode(key string, data []byte) (interface{}, error)

func (*BinaryCoder) Encode

func (c *BinaryCoder) Encode(key string, data interface{}) ([]byte, error)

func (*BinaryCoder) Register

func (c *BinaryCoder) Register(key uint32, decoder BinaryDecoder)

type BinaryDecoder

type BinaryDecoder interface {
	Unmarshal(data []byte) (interface{}, error)
}

type BinaryValue

type BinaryValue interface {
	TypeID() uint32
	Marshal() (data []byte, err error)
}

type Cache

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

func New

func New(store Store, opt ...Option) (c *Cache, e error)

func (*Cache) ClearBeans

func (c *Cache) ClearBeans(tableName string)

func (*Cache) ClearIds

func (c *Cache) ClearIds(tableName string)

func (*Cache) DelBean

func (c *Cache) DelBean(tableName string, id string)

func (*Cache) DelIds

func (c *Cache) DelIds(tableName, sql string)

func (*Cache) GetBean

func (c *Cache) GetBean(tableName string, id string) interface{}

func (*Cache) GetIds

func (c *Cache) GetIds(tableName, sql string) interface{}

func (*Cache) PutBean

func (c *Cache) PutBean(tableName string, id string, obj interface{})

func (*Cache) PutIds

func (c *Cache) PutIds(tableName, sql string, ids interface{})

type Coder

type Coder interface {
	Encode(key string, data interface{}) ([]byte, error)
	Decode(key string, data []byte) (interface{}, error)
}

How to encode and decode cached bean to interact with backend storage devices

type GobCoder

type GobCoder struct{}

func (GobCoder) Decode

func (c GobCoder) Decode(key string, data []byte) (interface{}, error)

func (GobCoder) Encode

func (c GobCoder) Encode(key string, data interface{}) ([]byte, error)

type JsonCoder

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

func DefaultCoder

func DefaultCoder() *JsonCoder

func NewJsonCoder

func NewJsonCoder() *JsonCoder

func (*JsonCoder) Decode

func (c *JsonCoder) Decode(key string, data []byte) (interface{}, error)

func (*JsonCoder) Encode

func (c *JsonCoder) Encode(key string, data interface{}) ([]byte, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCoder

func WithCoder(coder Coder) Option

func WithKeyPrefix

func WithKeyPrefix(prefix string) Option

func WithKeySeparators

func WithKeySeparators(sep string) Option

func WithLogger

func WithLogger(logger *log.Logger) Option

type Store

type Store interface {
	Put(key string, value []byte) error
	Get(key string) ([]byte, error)
	Del(key string) error
	DelPrefix(prefix string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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