clearv1

import clearv1 "pocketone.dev/ext/contracts/cache/clear/v1"

Package clearv1 is the cache.clear/v1 contract: empty an app's cache buckets from outside the app's code, so its admins (the dashboard, `pocketone remote cache clear`, an agent) can drop what cache/v1 keeps for it after a change that left stale entries behind.

A wire contract at /api/_c/cache.clear/v1, beside cache/v1: whoever provides cache/v1 provides this too.

Source: ext/contracts/cache/clear/v1.

Variables

var Contract = extkit.NewContract[Clearer]("cache.clear/v1", extkit.One)

Contract is cache.clear/v1.

var W = extkit.NewWire(Contract, "cache", func(inner Clearer, g *extkit.Guard[Clearer]) Clearer {
	return &guardClearer{inner, g}
},
	extkit.Op[Clearer]{
		Name:   "clear",
		Desc:   "Empties one of the app's cache buckets, or every bucket it has.",
		Method: "POST",
		Path:   "",
		Scope:  "cache",
		In:     reflect.TypeOf(ClearInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Clearer, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in ClearInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Clear(ctx, a, in)
		},
	},
)

W is cache.clear/v1's wire side: routes at /api/_c/cache.clear/v1/<op>, action hooks, MCP tools and the client.

Functions

OnClear

func OnClear(owner any, fn func(e *extkit.CallEvent, in *ClearInput) error)

OnClear binds fn to clear calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

Types

ClearInput

type ClearInput struct {
	Bucket string `json:"bucket,omitempty"` // one bucket by name; "" empties every bucket of the app
}

ClearInput says what to empty.

ClearResult

type ClearResult struct {
	Keys int `json:"keys"` // keys removed
}

ClearResult says what went.

Clearer

type Clearer interface {
	// Clear empties one of the app's cache buckets, or every bucket it has.
	//
	//op: POST / scope=cache
	Clear(ctx context.Context, a extkit.Auth, in ClearInput) (ClearResult, error)
}

Clearer empties an app's cache buckets.

Client

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

Client is cache.clear/v1 over HTTP, for the CLI and other apps. It implements Clearer; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls cache.clear/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Clear

func (c *Client) Clear(ctx context.Context, _ extkit.Auth, in ClearInput) (ClearResult, error)