cache

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

A wrapper for LRU/LFU cache used by httransform

The thing is that there are many (good) caching libraries available in Go. So many so I even think to make my own. But the truth is that I feel a huge discomfort leaking implemetation details in the rest of the code base. When I add a parameter which is unique only for specific implementation and we have to support it until end of the life.

So, the idea of this package is to introduce a minimal interface I'm going to use for httransform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoopEvictCallback

func NoopEvictCallback(_ string, _ interface{})

NoopEvictCallback implements EvictCallback which does nothing.

Types

type EvictCallback

type EvictCallback func(string, interface{})

EvictCallback is going to be executed on an entry eviction.

type Interface

type Interface interface {
	// Add puts a value into the cache.
	Add(key string, value interface{})

	// Get extracts value from the cache. If it is impossible to return
	// a value, then it returns a nil.
	Get(key string) interface{}
}

Interface defines a minimal set of methods and their signatures which is going to be used everywhere in this library.

func New

func New(size int, ttl time.Duration, callback EvictCallback) Interface

New returns a new LRU/LFU cache based on given parameters.

Jump to

Keyboard shortcuts

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