nearcache

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package nearcache contains the configuration and data types for the Near Cache.

Checkout the Map documentation for an overview of the Near Cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Eviction is the optional eviction configuration for the Near Cache.
	Eviction EvictionConfig

	// Name is the name of this Near Cache configuration.
	// If the name is not specified, it is set to "default".
	Name string
	// Must be non-negative.
	// The value 0 means math.MaxInt32
	// The default is 0.
	TimeToLiveSeconds int
	// MaxIdleSeconds is the maximum number of seconds each entry can stay in the Near Cache as untouched (not-read).
	// Entries that are not read (touched) more than MaxIdleSeconds value will get removed from the Near Cache.
	// Accepts any integer between {@code 0} and {@link Integer#MAX_VALUE}.
	// Must be non-negative.
	// The value 0 means math.MaxInt32
	// The default is 0.
	MaxIdleSeconds int
	// SerializeKeys specifies how the entry keys are stored in the Near Cache.
	// If false, keys are stored in their original form.
	// If true, keys are stored after serializing them.
	// Storing keys in serialized form is required when the key is not hashable, such as slices.
	// The default is false.
	SerializeKeys bool
	// InMemoryFormat specifies how the entry values are stored in the Near Cache.
	// InMemoryFormatBinary stores the values after serializing them.
	// InMemoryFormatObject stores the values in their original form.
	// The default is InMemoryFormatBinary.
	InMemoryFormat InMemoryFormat
	// contains filtered or unexported fields
}

Config is the Near Cache configuration.

func (Config) Clone

func (c Config) Clone() Config

Clone returns a copy of the configuration.

func (Config) InvalidateOnChange

func (c Config) InvalidateOnChange() bool

InvalidateOnChange returns true when invalidate on change is enabled. See the documentation for SetInvalidateOnChange.

func (Config) MarshalJSON

func (c Config) MarshalJSON() ([]byte, error)

func (*Config) SetInvalidateOnChange

func (c *Config) SetInvalidateOnChange(enabled bool)

SetInvalidateOnChange sets if Near Cache entries are invalidated when the entries in the backing data structure are changed (updated or removed). When this setting is enabled, a client with a Near Cache listens for cluster-wide changes on the entries of the backing data structure. And the client invalidates its corresponding Near Cache entries. Changes done on the client always invalidate the Near Cache immediately. Invalidate on change is true by default.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(b []byte) error

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration and replaces missing configuration with defaults.

type EvictableEntryView

type EvictableEntryView interface {
	// Hits is the number of accesses to the entry.
	Hits() int64
	// Key is the key of the entry.
	Key() interface{}
	// Value is the value of the entry.
	Value() interface{}
	// CreationTime is the creation time of the entry in milliseconds.
	CreationTime() int64
	// LastAccessTime is the time when the entry was last accessed in milliseconds.
	LastAccessTime() int64
}

EvictableEntryView is the contract point from the end user perspective for serving/accessing entries that can be evicted.

type EvictionConfig

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

EvictionConfig is the configuration for eviction.

You can set a limit for number of entries. The default values of the eviction configuration are:

  • EvictionPolicyLRU as eviction policy
  • 10_000 as maximum size for Map.

Eviction policy and comparator are mutually exclusive.

func (EvictionConfig) Clone

func (c EvictionConfig) Clone() EvictionConfig

Clone returns a copy of the configuration.

func (EvictionConfig) Comparator

Comparator returns the eviction policy comparator.

func (EvictionConfig) MarshalJSON

func (c EvictionConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals the eviction config to a byte array.

func (EvictionConfig) Policy

func (c EvictionConfig) Policy() EvictionPolicy

Policy returns the eviction policy of this eviction configuration. See the documentation for SetPolicy.

func (*EvictionConfig) SetComparator

func (c *EvictionConfig) SetComparator(cmp EvictionPolicyComparator)

SetComparator sets the eviction policy comparator.

func (*EvictionConfig) SetPolicy

func (c *EvictionConfig) SetPolicy(policy EvictionPolicy)

SetPolicy sets the eviction policy of this eviction configuration. The default policy is EvictionPolicyLRU which evicts the least recently used entries.

func (*EvictionConfig) SetSize

func (c *EvictionConfig) SetSize(size int)

SetSize sets the number of maximum entries before an eviction occurs. Accepts any non-negative number. The default value is 10_000.

func (EvictionConfig) Size

func (c EvictionConfig) Size() int

Size returns the number of maximum entries before an eviction occurs. See the documentation for SetSize.

func (*EvictionConfig) UnmarshalJSON

func (c *EvictionConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the eviction config from a byte array.

func (*EvictionConfig) Validate

func (c *EvictionConfig) Validate() error

Validate validates the configuration and sets the defaults.

type EvictionPolicy

type EvictionPolicy int32

EvictionPolicy specifies which entry is evicted.

const (
	// EvictionPolicyLRU removes the least recently used entry.
	EvictionPolicyLRU EvictionPolicy = iota
	// EvictionPolicyLFU removes the least frequently used entry.
	EvictionPolicyLFU
	// EvictionPolicyNone removes no entries.
	EvictionPolicyNone
	// EvictionPolicyRandom removes a random entry.
	EvictionPolicyRandom
)

func (EvictionPolicy) MarshalText

func (p EvictionPolicy) MarshalText() ([]byte, error)

MarshalText marshals EvictionPolicy to text.

func (EvictionPolicy) String

func (p EvictionPolicy) String() string

String returns a string representation of the eviction policy.

func (*EvictionPolicy) UnmarshalText

func (p *EvictionPolicy) UnmarshalText(b []byte) error

UnmarshalText unmarshals the given byte array to an EvictionPolicy.

type EvictionPolicyComparator

type EvictionPolicyComparator interface {
	// Compare returns a negative integer if a is less than b, 0 if a is equal to b or a positive integer if a is greater than b.
	Compare(a, b EvictableEntryView) int
}

EvictionPolicyComparator is used for comparing entries to be evicted.

type InMemoryFormat

type InMemoryFormat int8

InMemoryFormat specifies how the entry values are stored in the Near Cache.

const (
	// InMemoryFormatBinary stores the values after serializing them.
	InMemoryFormatBinary InMemoryFormat = iota
	// InMemoryFormatObject stores the values in their original form.
	InMemoryFormatObject
)

func (InMemoryFormat) MarshalText

func (m InMemoryFormat) MarshalText() ([]byte, error)

MarshalText marshals the text in memory format to a byte array.

func (*InMemoryFormat) UnmarshalText

func (m *InMemoryFormat) UnmarshalText(b []byte) error

UnmarshalText unmarshals the in memory format from a byte array.

type Stats

type Stats struct {
	// InvalidationRequests is the number of times an invalidation was requested.
	InvalidationRequests int64
	// Misses is the number of times an entry was not found in the Near Cache.
	Misses int64
	// Hits is the number of times an entry was found in the Near Cache.
	Hits int64
	// Expirations is the number of expirations due to TTL and max idle constraints.
	Expirations int64
	// Evictions is the number of evictions.
	Evictions int64
	// OwnedEntryCount is the number of entries in the Near Cache.
	OwnedEntryCount int64
	// OwnedEntryMemoryCost is the estimated memory cost in bytes for the entries in the Near Cache.
	OwnedEntryMemoryCost int64
	// Invalidations is the number of successful invalidations.
	Invalidations int64
	// LastPersistenceKeyCount is the number of keys saved in the last persistence task when the pre-load feature is enabled.
	LastPersistenceKeyCount int64
	// LastPersistenceWrittenBytes is number of bytes written in the last persistence task when the pre-load feature is enabled.
	LastPersistenceWrittenBytes int64
	// PersistenceCount is the number of completed persistence tasks when the pre-load feature is enabled.
	PersistenceCount int64
	// CreationTime is the time the Near Cache was initialized.
	CreationTime time.Time
	// LastPersistenceTime is the time of the last completed persistence task when the pre-load feature is enabled.
	LastPersistenceTime time.Time
	// LastPersistenceFailure is the error message of the last completed persistence task when the pre-load feature is enabled.
	LastPersistenceFailure string
	// LastPersistenceDuration is the duration of the last completed persistence task when the pre-load feature is enabled.
	LastPersistenceDuration time.Duration
}

Stats contains statistics for a Near Cache instance.

func (Stats) Ratio

func (s Stats) Ratio() float64

Ratio returns the ratio of hits to misses. Returns math.Nan if there were no hits and misses. Otherwise returns +math.Inf if there were no misses.

Jump to

Keyboard shortcuts

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