rpccache

package
v0.0.0-...-b81b7c8 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is an expiring, stale-checking LRU of keys to multiple values.

func New

func New(opts Options) *Cache

New constructs a new Cache with the Options.

func (*Cache) Close

func (c *Cache) Close() (err error)

Close removes every value from the cache and closes it if necessary.

func (*Cache) Put

func (c *Cache) Put(key, val interface{})

Put places the connection in to the cache with the provided key. It returns any errors closing any connections necessary to do the job.

func (*Cache) Take

func (c *Cache) Take(key interface{}) interface{}

Take acquires a value from the cache if one exists. It returns nil if one does not.

type Options

type Options struct {
	// Expiration will remove any values from the Cache after the
	// value passes. Zero means no expiration.
	Expiration time.Duration

	// Capacity is the maximum number of values the Cache can store.
	// Zero means unlimited. Negative means no values.
	Capacity int

	// KeyCapacity is like Capacity except it is per key. Zero means
	// the Cache holds unlimited for any single key. Negative means
	// no values for any single key.
	//
	// Implementation note: The cache is potentially quadratic in the
	// size of this parameter, so it is intended for small values, like
	// 5 or so.
	KeyCapacity int

	// Stale is optionally called on values before they are returned
	// to see if they should be discarded. Nil means no check is made.
	Stale func(interface{}) bool

	// Close is optionally called on any value removed from the Cache.
	Close func(interface{}) error

	// Unblocked is optional and called on values before they are returned
	// to see if they are available to be used. Nil means no check is made.
	Unblocked func(interface{}) bool
}

Options contains the options to configure a cache.

Jump to

Keyboard shortcuts

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