cache

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: Unlicense Imports: 3 Imported by: 13

Documentation

Overview

Package cache provides a simple LRU cache implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set data
	// Return FALSE if data was added;  TRUE if data was replaced
	Set(key []byte, val []byte) bool

	// Get data
	// Return nil if item with this key doesn't exist
	Get(key []byte) []byte

	// Delete data
	Del(key []byte)

	// Clear all data and statistics
	Clear()

	// Get statistics data
	Stats() Stats
}

Cache - interface

func New

func New(conf Config) Cache

New - create cache object

type Config

type Config struct {
	// Max. cache size (in bytes) of keys and values.  Default: unlimited
	MaxSize uint

	// Max. element size (in bytes).  Default: =MaxSize
	MaxElementSize uint

	// Max. elements number.  Default: unlimited
	MaxCount uint

	// When cache is full, the least recently used element is deleted automatically
	EnableLRU bool

	// User callback function which is called after an element has been deleted automatically
	OnDelete onDeleteType
}

Config - configuration

type Stats

type Stats struct {
	Count int
	Size  int
	Hit   int
	Miss  int
}

Stats - counters

Jump to

Keyboard shortcuts

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