cache

package
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfiguredObjectCache

type ConfiguredObjectCache = ObjectCache[*pb.ConfiguredKubernetesObjectData]

ConfiguredObjectCache is the cache type for CloudSecure configured objects.

func NewConfiguredObjectCache

func NewConfiguredObjectCache() *ConfiguredObjectCache

NewConfiguredObjectCache creates a new cache for configured objects.

type ObjectCache

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

ObjectCache is a generic thread-safe cache for storing objects by ID. It supports atomic replacement for snapshot-based updates.

This cache is generic to support both:

  • Config cache: stores *pb.ConfiguredKubernetesObjectData from CloudSecure (desired state)
  • Runtime cache: stores *unstructured.Unstructured from Kubernetes (actual state)

Access patterns:

  • Snapshot: Build a local map, then call ReplaceAll() to atomically swap it in
  • Mutations: Use Insert() and Delete() which handle locking internally
  • Reading: Use Get(), Values(), Len() which handle locking internally

Block on <-cache.IsReady() to wait for the first snapshot to complete before reading.

func NewObjectCache

func NewObjectCache[T any]() *ObjectCache[T]

NewObjectCache creates a new cache instance.

func (*ObjectCache[T]) Delete

func (c *ObjectCache[T]) Delete(id string)

Delete removes an object from the cache by ID. Use for mutations after snapshot is complete.

func (*ObjectCache[T]) Get

func (c *ObjectCache[T]) Get(id string) T

Get retrieves an object by ID. Returns the zero value if not found.

func (*ObjectCache[T]) Insert

func (c *ObjectCache[T]) Insert(id string, obj T)

Insert adds or updates an object in the cache. Use for mutations after snapshot is complete.

func (*ObjectCache[T]) IsReady

func (c *ObjectCache[T]) IsReady() <-chan struct{}

IsReady returns a channel that is closed when the first snapshot is complete. Use <-cache.IsReady() to block until the cache has consistent data.

func (*ObjectCache[T]) Len

func (c *ObjectCache[T]) Len() int

Len returns the number of objects in the cache.

func (*ObjectCache[T]) ReplaceAll

func (c *ObjectCache[T]) ReplaceAll(objects map[string]T)

ReplaceAll atomically replaces all objects in the cache with the provided map. Use this for snapshot ingestion: build a local map, then call ReplaceAll to swap it in. The cache remains consistent until the swap completes. Also marks the cache as ready on first call to indicate cache now has valid data.

func (*ObjectCache[T]) Values

func (c *ObjectCache[T]) Values() []T

Values returns all objects in the cache, sorted by ID for consistency.

Jump to

Keyboard shortcuts

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