cache

package
v0.0.0-...-d277e4d Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache maintains in-memory collections/entries and emits typed events on mutation. It mirrors the behavior of a Kubernetes-style informer cache: state lives locally, watchers subscribe to emitted events, and consumers read consistent snapshots without hitting the store.

func New

func New(component events.ComponentID) *Cache

New creates an empty cache that will emit events using the provided ComponentID (falls back to "cache" if empty).

func NewWithOptions

func NewWithOptions(opts Options) *Cache

NewWithOptions constructs a cache using the supplied options.

func (*Cache) ApplySnapshot

func (c *Cache) ApplySnapshot(snapshot Snapshot)

ApplySnapshot reconciles the cache with the provided snapshot, emitting collection/bullet change events for any detected differences.

func (*Cache) CollectionsMeta

func (c *Cache) CollectionsMeta() []collection.Meta

CollectionsMeta returns a copy of the cached collection metadata list.

func (*Cache) ComponentID

func (c *Cache) ComponentID() events.ComponentID

ComponentID returns the cache instance identifier used for emitted events.

func (*Cache) CreateBullet

func (c *Cache) CreateBullet(collectionID string, bullet collectiondetail.Bullet) error

CreateBullet appends a bullet to the specified collection, emits a bullet change message, and returns the updated section.

func (*Cache) CreateBulletWithMeta

func (c *Cache) CreateBulletWithMeta(collectionID string, bullet collectiondetail.Bullet, meta map[string]string) error

CreateBulletWithMeta mirrors CreateBullet but allows callers to specify additional metadata (e.g., parent assignment).

func (*Cache) CreateBulletWithMetaContext

func (c *Cache) CreateBulletWithMetaContext(ctx context.Context, collectionID string, bullet collectiondetail.Bullet, meta map[string]string) error

CreateBulletWithMetaContext mirrors CreateBulletWithMeta but allows callers to supply the context used for persistence calls.

func (*Cache) CreateCollection

func (c *Cache) CreateCollection(meta collection.Meta) []*viewmodel.ParsedCollection

CreateCollection inserts metadata and emits a CollectionChangeMsg. It returns the parsed tree for the new state.

func (*Cache) DeleteBullet

func (c *Cache) DeleteBullet(collectionID, bulletID string)

DeleteBullet removes the specified bullet ID from the collection and emits a delete change message.

func (*Cache) DeleteCollection

func (c *Cache) DeleteCollection(name string) []*viewmodel.ParsedCollection

DeleteCollection removes a collection (and children) and emits a delete change message.

func (*Cache) Events

func (c *Cache) Events() <-chan tea.Msg

Events exposes the cache event channel for Bubble Tea subscriptions.

func (*Cache) RegisterSectionTemplate

func (c *Cache) RegisterSectionTemplate(section collectiondetail.Section)

RegisterSectionTemplate stores presentation metadata for a collection so future dynamically created sections inherit the correct title/subtitle.

func (*Cache) SectionSnapshot

func (c *Cache) SectionSnapshot(id string) (collectiondetail.Section, bool)

SectionSnapshot returns a copy of the requested section.

func (*Cache) SetCollections

func (c *Cache) SetCollections(metas []collection.Meta)

SetCollections seeds the cache with the provided metadata list. It rebuilds the parsed tree and emits no events (callers should emit ChangeMsgs if desired). Safe to call multiple times (it replaces state).

func (*Cache) SetSections

func (c *Cache) SetSections(sections []collectiondetail.Section)

SetSections seeds the detail sections backing the collection detail pane.

func (*Cache) SetService

func (c *Cache) SetService(svc Service)

SetService wires the cache to a persistence-backed Service for writes.

func (*Cache) Snapshot

func (c *Cache) Snapshot() Snapshot

Snapshot returns a copy of the current parsed collections and sections. The returned data should be treated as immutable by callers.

func (*Cache) SyncCollection

func (c *Cache) SyncCollection(ctx context.Context, collectionID string) error

SyncCollection refreshes a single collection detail section from the configured service, emitting bullet diff events.

func (*Cache) UpdateBullet

func (c *Cache) UpdateBullet(collectionID string, bullet collectiondetail.Bullet)

UpdateBullet replaces an existing bullet (matched by ID) and emits an update.

func (*Cache) UpdateCollection

func (c *Cache) UpdateCollection(current collection.Meta, previous *collection.Meta) []*viewmodel.ParsedCollection

UpdateCollection applies metadata changes and emits an Update change message.

type Options

type Options struct {
	Component events.ComponentID
	Service   Service
	Clock     clock.Clock
}

Options configure cache construction.

type Service

type Service interface {
	CollectionsMeta(ctx context.Context, prefix string) ([]collection.Meta, error)
	Entries(ctx context.Context, collectionID string) ([]*entry.Entry, error)
	Add(ctx context.Context, collection string, bullet glyph.Bullet, msg string, sig glyph.Signifier) (*entry.Entry, error)
	SetParent(ctx context.Context, id, parentID string) (*entry.Entry, error)
}

Service describes the journal data access needed by the cache.

type Snapshot

type Snapshot struct {
	Metas       []collection.Meta
	Collections []*viewmodel.ParsedCollection
	Sections    []collectiondetail.Section
}

Snapshot exposes the current cached state.

func BuildSnapshot

func BuildSnapshot(ctx context.Context, svc Service) (Snapshot, error)

BuildSnapshot loads collection metadata and entry sections from the supplied service, assembling a cache snapshot that mirrors on-disk state.

func BuildSnapshotWithClock

func BuildSnapshotWithClock(ctx context.Context, svc Service, clk clock.Clock) (Snapshot, error)

BuildSnapshotWithClock loads metadata and entries using the provided clock.

Jump to

Keyboard shortcuts

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