Skip to content

Add Cache.EarliestManagedExpiration - #413

Open
IslamElsayed wants to merge 1 commit into
caddyserver:masterfrom
IslamElsayed:earliest-managed-expiration
Open

IslamElsayed wants to merge 1 commit into
caddyserver:masterfrom
IslamElsayed:earliest-managed-expiration

Conversation

@IslamElsayed

Copy link
Copy Markdown

Adds a small aggregate method on Cache that returns the earliest expiration among the managed certificates in the cache, and false if there are none. It's for the expiry gauge in caddyserver/caddy#1683, where @steadytao asked for it to come from CertMagic rather than be rebuilt from events.

It walks the cache under the read lock, so it's meant for occasional callers such as a metrics scrape. It uses the package's own expiresAt, and skips unmanaged certificates and any without a parsed leaf.

TestEarliestManagedExpiration covers an empty cache, a cache with only unmanaged certificates, and managed certificates with different expirations.

(I used AI assistance, Claude, while preparing this; I reviewed and tested it myself.)

Returns the earliest expiration among the managed certificates in the cache, for metrics such as the expiry gauge requested in caddyserver/caddy#1683.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants