cache

package
v0.0.0-...-2208570 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package cache provides an object cache that uses an adaptive replacement policy described by Mediddo & Modha in "Outperforming LRU with an Adaptive Replacement Cache Algorithm".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackingStore

type BackingStore interface {
	// Get is called by the cache when a requested key is not found in the cache and needs
	// to be read in from the BackingStore.
	Get(Key) Value

	// Put is called by the cache when a dirty entry is flushed and should be committed to
	// the BackingStore.
	Put(Key, Value)
}

BackingStore defines the interface that the cache expects from the storage medium for which it is acting as a cache.

type C

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

C represents an object cache.

func New

func New(size int, bs BackingStore) *C

New returns a new, initialized Adaptive Replacement Cache.

func (*C) Flush

func (c *C) Flush()

Flush commits all dirty Entries in the cache to the BackingStore.

func (*C) Get

func (c *C) Get(k Key) *Entry

Get returns the Entry containing the Value for the Key k, fetching it from the BackingStore if necessary. Callers _must_ set the IsDirty field for the returned Entry if they change the Value in the Entry to ensure that the change is propagated to the BackingStore. Callers must also not retain the returned Entry.

func (*C) Put

func (c *C) Put(k Key, v Value)

Put associates the Value v with the Key k and stores it in the cache. It additionally marks the Entry dirty so that the new Value will be propagated to the BackingStore. Callers may wish to use Put when they want to completely replace the Value associated with some Key and want to avoid a potentially expensive lookup for the Key in the BackingStore.

type Entry

type Entry struct {

	// The value associated with the key for this entry.
	Value Value

	// Indicates whether this entry has been modified.  Callers must set this field
	// to true when they modify Value.  The cache will only commit this Entry to the BackingStore
	// if IsDirty is true.
	IsDirty bool
	// contains filtered or unexported fields
}

Entry represents a single entry in the cache.

type Key

type Key interface{}

Key represents a key to an object in the cache.

type Value

type Value interface{}

Value represents a value associated with a key in the cache.

Jump to

Keyboard shortcuts

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