agdcache

package
v0.0.0-...-f179113 Latest Latest
Warning

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

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

Documentation

Overview

Package agdcache contains cache interfaces, helpers, and implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clearer

type Clearer interface {
	// Clear completely clears cache.
	Clear()
}

Clearer is a partial cache interface.

type DefaultManager

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

DefaultManager implements the Manager interface that stores caches and can clear them by id

func NewDefaultManager

func NewDefaultManager() (m *DefaultManager)

NewDefaultManager returns a new initialized *DefaultManager.

func (*DefaultManager) Add

func (m *DefaultManager) Add(id string, cache Clearer)

Add implements the Manager interface for *DefaultManager. Note that it replaces the saved cache with the same id if there is one.

func (*DefaultManager) ClearByID

func (m *DefaultManager) ClearByID(id string)

ClearByID implements the Manager interface for *DefaultManager.

func (*DefaultManager) IDs

func (m *DefaultManager) IDs() (ids []string)

IDs returns a sorted list of stored cache identifiers.

type Empty

type Empty[K, T any] struct{}

Empty is an Interface implementation that does nothing.

func (Empty[K, T]) Clear

func (c Empty[K, T]) Clear()

Clear implements the Interface interface for Empty.

func (Empty[K, T]) Get

func (c Empty[K, T]) Get(key K) (val T, ok bool)

Get implements the Interface interface for Empty.

func (Empty[K, T]) Len

func (c Empty[K, T]) Len() (n int)

Len implements the Interface interface for Empty. n may include items that have expired, but have not yet been cleaned up.

func (Empty[K, T]) Set

func (c Empty[K, T]) Set(key K, val T)

Set implements the Interface interface for Empty.

func (Empty[K, T]) SetWithExpire

func (c Empty[K, T]) SetWithExpire(key K, val T, expiration time.Duration)

SetWithExpire implements the Interface interface for Empty.

type EmptyManager

type EmptyManager struct{}

EmptyManager implements the Manager interface that does nothing.

func (EmptyManager) Add

func (EmptyManager) Add(_ string, _ Clearer)

Add implements the Manager interface for *EmptyManager.

func (EmptyManager) ClearByID

func (EmptyManager) ClearByID(_ string)

ClearByID implements the Manager interface for *EmptyManager.

type Interface

type Interface[K, T any] interface {
	// Set sets key and val as cache pair.
	Set(key K, val T)

	// SetWithExpire sets key and val as cache pair with expiration time.
	SetWithExpire(key K, val T, expiration time.Duration)

	// Get gets val from the cache using key.
	Get(key K) (val T, ok bool)

	// Clearer completely clears cache.
	Clearer

	// Len returns the number of items in the cache.
	Len() (n int)
}

Interface is the cache interface.

type LRU

type LRU[K, T any] struct {
	// contains filtered or unexported fields
}

LRU is an Interface implementation.

func NewLRU

func NewLRU[K, T any](conf *LRUConfig) (c *LRU[K, T])

NewLRU returns a new initialized LRU cache.

func (*LRU[K, T]) Clear

func (c *LRU[K, T]) Clear()

Clear implements the Interface interface for *LRU.

func (*LRU[K, T]) Get

func (c *LRU[K, T]) Get(key K) (val T, ok bool)

Get implements the Interface interface for *LRU.

func (*LRU[K, T]) Len

func (c *LRU[K, T]) Len() (n int)

Len implements the Interface interface for *LRU. n may include items that have expired, but have not yet been cleaned up.

func (*LRU[K, T]) Set

func (c *LRU[K, T]) Set(key K, val T)

Set implements the Interface interface for *LRU.

func (*LRU[K, T]) SetWithExpire

func (c *LRU[K, T]) SetWithExpire(key K, val T, expiration time.Duration)

SetWithExpire implements the Interface interface for *LRU.

type LRUConfig

type LRUConfig struct {
	// Count is the maximum number of elements to keep in the cache.  It must be
	// positive.
	//
	// TODO(a.garipov):  Make uint64.
	Count int
}

LRUConfig is a configuration structure of a cache.

type Manager

type Manager interface {
	// Add adds cache by id.  cache must not be nil.
	//
	// TODO(s.chzhen):  Add Set method that rewrites the cache associated with
	// id (current Add implementation).
	//
	// TODO(s.chzhen):  Add panic on adding cache with duplicate id.
	Add(id string, cache Clearer)

	// ClearByID clears cache by id.
	ClearByID(id string)
}

Manager is the cache manager interface. All methods must be safe for concurrent use.

Jump to

Keyboard shortcuts

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