lifo

package
v0.0.0-...-7dc01ea Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lifo enables caching bytes of data using an in-memory Last-In-First-Out cache.

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 represents an in-memory Last In First Out cache that is safe to use for concurrent writes from multiple goroutines.

func New

func New(size int) (*Cache, error)

New creates and returns a LIFO (Last In First Out) cache with a maximum size specified in bytes. The cache size must be a number greater than 0, otherwise en error will be returned.

func (*Cache) Clr

func (c *Cache) Clr()

Clr removes and clears every item from the cache, and resets its size.

func (*Cache) Del

func (c *Cache) Del(key string) []byte

Del deletes a key from the cache. If the value existed in the cache then the value is returned, otherwise a nil byte slice is returned.

func (*Cache) Get

func (c *Cache) Get(key string) []byte

Get looks up a key's value in the cache. If the value exists in the cache then the value is returned, otherwise a nil byte slice is returned.

func (*Cache) Has

func (c *Cache) Has(key string) bool

Has checks to see if the key exists in the cache, returning a true if it exists and false if not.

func (*Cache) Put

func (c *Cache) Put(key string, val []byte) []byte

Put puts a new item into the cache using the specified key. If the size of the cache will rise above the allowed cache size, the oldest items will be removed.

Jump to

Keyboard shortcuts

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