cache

package
v1.10.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cache implements some cache utils.

Index

Constants

View Source
const (
	// DefaultTTL is the duration for which we keep entries in the cache.
	DefaultTTL = 10 * time.Minute
)

Variables

This section is empty.

Functions

func NewReconcileEntryKey

func NewReconcileEntryKey(obj metav1.Object) string

NewReconcileEntryKey returns the key of a ReconcileEntry based on an object.

Types

type Cache

type Cache[E Entry] interface {
	// Add adds the given entry to the Cache.
	// Note: entries expire after the ttl.
	Add(entry E)

	// Has checks if the given key (still) exists in the Cache.
	// Note: entries expire after the ttl.
	Has(key string) (E, bool)
}

Cache caches objects of type Entry.

func New

func New[E Entry](ttl time.Duration) Cache[E]

New creates a new cache. ttl is the duration for which we keep entries in the cache.

type Entry

type Entry interface {
	// Key returns the cache key of an Entry.
	Key() string
}

Entry is the interface for the type of Cache entries.

type ReconcileEntry

type ReconcileEntry struct {
	Request        ctrl.Request
	ReconcileAfter time.Time
}

ReconcileEntry is an Entry for the Cache that stores the earliest time after which the next Reconcile should be executed.

func NewReconcileEntry

func NewReconcileEntry(obj metav1.Object, reconcileAfter time.Time) ReconcileEntry

NewReconcileEntry creates a new ReconcileEntry based on an object and a reconcileAfter time.

func (ReconcileEntry) Key

func (r ReconcileEntry) Key() string

Key returns the cache key of a ReconcileEntry.

func (ReconcileEntry) ShouldRequeue

func (r ReconcileEntry) ShouldRequeue(now time.Time) (requeueAfter time.Duration, requeue bool)

ShouldRequeue returns if the current Reconcile should be requeued.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳