cache

package
v0.0.0-...-f933b0b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Enable    = "enable"
	Endpoint  = "endpoint"
	BlockSize = "block_size"

	EnvEnable    = "MINIO_CACHE_ENABLE"
	EnvEndpoint  = "MINIO_CACHE_ENDPOINT"
	EnvBlockSize = "MINIO_CACHE_BLOCK_SIZE"
)

Cache related keys

Variables

View Source
var (
	ErrInvalidArgument = errors.New("invalid argument")
	ErrKeyMissing      = errors.New("key is missing")
)

cache related errors

View Source
var DefaultKVS = config.KVS{
	config.KV{
		Key:   Enable,
		Value: "off",
	},
	config.KV{
		Key:   Endpoint,
		Value: "",
	},
	config.KV{
		Key:   BlockSize,
		Value: "",
	},
}

DefaultKVS - default KV config for cache settings

View Source
var (

	// Help - provides help for cache config
	Help = config.HelpKVS{
		config.HelpKV{
			Key:         Enable,
			Type:        "on|off",
			Description: "set to enable remote cache plugin" + defaultHelpPostfix(Enable),
			Optional:    true,
		},
		config.HelpKV{
			Key:         Endpoint,
			Type:        "string",
			Description: "remote cache endpoint for GET/HEAD object(s) metadata, data" + defaultHelpPostfix(Endpoint),
			Optional:    true,
		},
		config.HelpKV{
			Key:         BlockSize,
			Type:        "string",
			Description: "cache all objects below the specified block size" + defaultHelpPostfix(BlockSize),
			Optional:    true,
		},
	}
)

Functions

This section is empty.

Types

type CondCheck

type CondCheck struct {
	ObjectInfo
	IfMatch           string     `json:"ifMatch,omitempty" msg:",omitempty"`
	IfNoneMatch       string     `json:"ifNoneMatch,omitempty" msg:",omitempty"`
	IfModifiedSince   *time.Time `json:"ifModSince,omitempty" msg:",omitempty"`
	IfUnModifiedSince *time.Time `json:"ifUnmodSince,omitempty" msg:",omitempty"`
	IfRange           string     `json:"ifRange,omitempty" msg:",omitempty"`
	IfPartNumber      int        `json:"ifPartNumber,omitempty" msg:",omitempty"`
}

CondCheck represents the conditional request made to the remote cache for validation during GET/HEAD object requests.

func (*CondCheck) DecodeMsg

func (z *CondCheck) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*CondCheck) EncodeMsg

func (z *CondCheck) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*CondCheck) Init

func (r *CondCheck) Init(bucket, object string, header http.Header)

Init - populates the input values, initializes CondCheck before sending the request remotely.

func (*CondCheck) IsSet

func (r *CondCheck) IsSet() bool

IsSet tells the cache lookup to avoid sending a request

func (*CondCheck) MarshalMsg

func (z *CondCheck) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*CondCheck) Msgsize

func (z *CondCheck) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*CondCheck) UnmarshalMsg

func (z *CondCheck) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Config

type Config struct {
	// Flag indicating whether cache is enabled.
	Enable bool `json:"enable"`

	// Endpoint for caching uses remote mcache server to
	// store and retrieve pre-condition check entities such as
	// Etag and ModTime of an object + version
	Endpoint string `json:"endpoint"`

	// BlockSize indicates the maximum object size below which
	// data is cached and fetched remotely from DRAM.
	BlockSize int64
	// contains filtered or unexported fields
}

Config represents the subnet related configuration

func LookupConfig

func LookupConfig(kvs config.KVS, transport http.RoundTripper) (cfg Config, err error)

LookupConfig - lookup config and override with valid environment settings if any.

func (Config) Delete

func (c Config) Delete(bucket, key string)

Delete deletes remote cached content for object and its version.

func (*Config) Enabled

func (c *Config) Enabled() bool

Enabled - indicates if cache is enabled or not

func (Config) Get

func (c Config) Get(r *CondCheck) (*ObjectInfo, error)

Get performs conditional check and returns the cached object info if any.

func (Config) MatchesSize

func (c Config) MatchesSize(size int64) bool

MatchesSize verifies if input 'size' falls under cacheable threshold

func (Config) Set

func (c Config) Set(ci *ObjectInfo)

Set sets the cache object info

func (*Config) Update

func (c *Config) Update(ncfg Config)

Update updates new cache frequency

type ObjectInfo

type ObjectInfo struct {
	Key        string    `json:"key"`
	Bucket     string    `json:"bucket"`
	ETag       string    `json:"etag"`
	ModTime    time.Time `json:"modTime"`
	StatusCode int       `json:"statusCode"`

	// Optional elements
	CacheControl string            `json:"cacheControl,omitempty" msg:",omitempty"`
	Expires      string            `json:"expires,omitempty" msg:",omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty" msg:",omitempty"`
	Range        string            `json:"range,omitempty" msg:",omitempty"`
	PartNumber   int               `json:"partNumber,omitempty" msg:",omitempty"`
	Size         int64             `json:"size,omitempty" msg:",omitempty"` // Full size of the object
	Data         []byte            `json:"data,omitempty" msg:",omitempty"` // Data can container full data of the object or partial
}

ObjectInfo represents the object information cached remotely

func (*ObjectInfo) DecodeMsg

func (z *ObjectInfo) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*ObjectInfo) EncodeMsg

func (z *ObjectInfo) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*ObjectInfo) MarshalMsg

func (z *ObjectInfo) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*ObjectInfo) Msgsize

func (z *ObjectInfo) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ObjectInfo) UnmarshalMsg

func (z *ObjectInfo) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (ObjectInfo) WriteHeaders

func (oi ObjectInfo) WriteHeaders(w http.ResponseWriter, preamble, statusCode func())

WriteHeaders writes the response headers for conditional requests

Jump to

Keyboard shortcuts

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