proxy

package
v1.6.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheKey

func CacheKey(contributor, resourceType, resourceID string) string

CacheKey generates a cache key for a contributor's page or widget.

Types

type CacheEntry

type CacheEntry struct {
	Data      []byte
	FetchedAt time.Time
	ExpiresAt time.Time
}

CacheEntry holds a cached HTML fragment with expiry tracking.

func (*CacheEntry) Age

func (e *CacheEntry) Age() time.Duration

Age returns how old this cache entry is.

func (*CacheEntry) IsExpired

func (e *CacheEntry) IsExpired() bool

IsExpired returns true if the cache entry has expired.

type FragmentCache

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

FragmentCache is an LRU+TTL cache for HTML fragments from remote contributors.

func NewFragmentCache

func NewFragmentCache(maxSize int, ttl time.Duration) *FragmentCache

NewFragmentCache creates a new fragment cache.

func (*FragmentCache) Clear

func (c *FragmentCache) Clear()

Clear removes all cached entries.

func (*FragmentCache) Delete

func (c *FragmentCache) Delete(key string)

Delete removes a cached entry.

func (*FragmentCache) Get

func (c *FragmentCache) Get(key string) *CacheEntry

Get retrieves a cached fragment. Returns nil if not found or expired.

func (*FragmentCache) GetStale

func (c *FragmentCache) GetStale(key string) *CacheEntry

GetStale retrieves a cached fragment even if expired. This is used by the recovery system to serve stale content when remotes are down.

func (*FragmentCache) Set

func (c *FragmentCache) Set(key string, data []byte)

Set stores a fragment in the cache.

func (*FragmentCache) Size

func (c *FragmentCache) Size() int

Size returns the number of cached entries.

type FragmentProxy

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

FragmentProxy fetches HTML fragments from remote contributors with caching. It provides the primary integration between the dashboard shell and remote services.

func NewFragmentProxy

func NewFragmentProxy(
	registry *contributor.ContributorRegistry,
	cacheMaxSize int,
	cacheTTL time.Duration,
	timeout time.Duration,
	logger forge.Logger,
) *FragmentProxy

NewFragmentProxy creates a new fragment proxy.

func (*FragmentProxy) Cache

func (p *FragmentProxy) Cache() *FragmentCache

Cache returns the underlying fragment cache (for metrics/status reporting).

func (*FragmentProxy) FetchPage

func (p *FragmentProxy) FetchPage(ctx context.Context, name, route, rawQuery string) ([]byte, error)

FetchPage fetches a page fragment from a remote contributor, using cache when available. rawQuery is the request URL's query string (without the leading "?"); it is forwarded to the remote and is part of the cache key so pages with different query parameters (e.g. /detail?id=A vs ?id=B) don't collide.

func (*FragmentProxy) FetchWidget

func (p *FragmentProxy) FetchWidget(ctx context.Context, name, widgetID string) ([]byte, error)

FetchWidget fetches a widget fragment from a remote contributor, using cache when available.

func (*FragmentProxy) InvalidateContributor

func (p *FragmentProxy) InvalidateContributor(name string)

InvalidateContributor removes all cached fragments for a contributor.

func (*FragmentProxy) PostPage added in v1.6.2

func (p *FragmentProxy) PostPage(ctx context.Context, name, route, rawQuery string, body io.Reader, contentType string) ([]byte, error)

PostPage proxies a form submission (POST) to a remote contributor's page endpoint. POSTs bypass the fragment cache — they're side-effecting and the response is bound to the request body, not the URL alone.

rawQuery carries the consumer-side bp/pb plus any inbound query the request URL had. body and contentType come straight from the host's inbound request (typically application/x-www-form-urlencoded or multipart/form-data).

Jump to

Keyboard shortcuts

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