memcache

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 6 Imported by: 6

README

Memcache

Memcache provider implementation.

Better encoder:

  • Encode: session.MSGPEncode
  • Decode: session.MSGPDecode

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigServerListEmpty  = errors.New("Config ServerList must not be empty")
	ErrConfigMaxIdleConnsZero = errors.New("Config MaxIdleConns must be more than 0")
	ErrExpirationIsTooBig     = errors.New("Expiration duration should be a 32 bits value")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Prefix key
	KeyPrefix string

	// Server list
	ServerList []string

	// The socket read/write timeout.
	// If zero, DefaultTimeout is used.
	Timeout time.Duration

	// The maximum number of idle connections that will
	// be maintained per address. If less than one, DefaultMaxIdleConns will be
	// used.
	//
	// Consider your expected traffic rates and latency carefully. This should
	// be set to a number higher than your peak parallel requests.
	MaxIdleConns int
}

Config provider settings

type Provider

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

Provider backend manager

func New

func New(cfg Config) (*Provider, error)

New returns a new memcache provider configured

func (*Provider) Count

func (p *Provider) Count() int

Count returns the total of stored sessions

func (*Provider) Destroy

func (p *Provider) Destroy(id []byte) error

Destroy destroys the session from the given id

func (*Provider) GC

func (p *Provider) GC() error

GC destroys the expired sessions

func (*Provider) Get

func (p *Provider) Get(id []byte) ([]byte, error)

Get returns the data of the given session id

func (*Provider) NeedGC

func (p *Provider) NeedGC() bool

NeedGC indicates if the GC needs to be run

func (*Provider) Regenerate

func (p *Provider) Regenerate(id, newID []byte, expiration time.Duration) error

Regenerate updates the session id and expiration with the new session id of the the given current session id

func (*Provider) Save

func (p *Provider) Save(id, data []byte, expiration time.Duration) error

Save saves the session data and expiration from the given session id

Jump to

Keyboard shortcuts

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