resultcache

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package resultcache contains a cache for filtering results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a wrapper around gcache.Cache to simplify rare error handling.

func New

func New[T any](size int) (c *Cache[T])

New returns a new LRU result cache with the given size.

func (*Cache[T]) Clear

func (c *Cache[T]) Clear()

Clear clears the cache. If c is nil, nothing is done.

func (*Cache[T]) Get

func (c *Cache[T]) Get(k Key) (r T, ok bool)

Get returns the cached result, if any. If c is nil, Get returns a zero T and false.

func (*Cache[T]) ItemCount

func (c *Cache[T]) ItemCount() (n int)

ItemCount returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up. If c is nil, ItemCount returns 0.

func (*Cache[T]) Set

func (c *Cache[T]) Set(k Key, r T)

Set sets the cached result. If c is nil, nothing is done.

type Key

type Key uint64

Key is the type of result cache keys.

func DefaultKey

func DefaultKey(host string, qt dnsmsg.RRType, cl dnsmsg.Class, isAns bool) (k Key)

DefaultKey produces a cache key based on host, qt, and isAns using the default algorithm.

Jump to

Keyboard shortcuts

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