memcached

package
v1.21.1-0...-8239ed6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

This package implements an image DB cache using memcached.

Items are given an expiry based on their refresh deadline, with a minimum duration to try and ensure things will expire well after they would have been refreshed (i.e., only if they truly need garbage collection).

memcached will still evict things when under memory pressure. We can recover from that -- we'll just get a cache miss, and fetch it again.

Index

Constants

View Source
const (
	// The minimum expiry given to an entry.
	MinExpiry = time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MemcacheClient

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

MemcacheClient is a memcache client that gets its server list from SRV records, and periodically updates that ServerList.

func NewFixedServerMemcacheClient

func NewFixedServerMemcacheClient(config MemcacheConfig, addresses ...string) *MemcacheClient

Does not use DNS, accepts static list of servers.

func NewMemcacheClient

func NewMemcacheClient(config MemcacheConfig) *MemcacheClient

func (*MemcacheClient) GetKey

func (c *MemcacheClient) GetKey(k cache.Keyer) ([]byte, time.Time, error)

GetKey gets the value and its refresh deadline from the cache.

func (*MemcacheClient) SetKey

func (c *MemcacheClient) SetKey(k cache.Keyer, refreshDeadline time.Time, v []byte) error

SetKey sets the value and its refresh deadline at a key. NB the key expiry is set _longer_ than the deadline, to give us a grace period in which to refresh the value.

func (*MemcacheClient) Stop

func (c *MemcacheClient) Stop()

Stop the memcache client.

type MemcacheConfig

type MemcacheConfig struct {
	Host           string
	Service        string
	Timeout        time.Duration
	UpdateInterval time.Duration
	Logger         log.Logger
	MaxIdleConns   int
}

MemcacheConfig defines how a MemcacheClient should be constructed.

Jump to

Keyboard shortcuts

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