Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Cache Policy Settings Block for React

An ordered table of cache rules where first match wins: each path pattern has a freshness bar, how long a copy stays fresh and how long a stale one may be served, a count of the cached paths it really claims, and a purge that counts what it would clear.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Show which cache rule a path actually gets, with this cache policy panel for React with Base UI. Inside a hairline frame with a plus mark on each corner, a native table lists the rules in the order they are tried: a path pattern in code, a bar that draws how long a copy stays fresh in solid and how long a stale one may be served while it refreshes in a lighter tone, a Number Input and a Native Select for the freshness and its unit, and a second Native Select for the stale window. The first rule that matches a path wins, so each rule says how many of eight cached paths it serves, or that an earlier rule shadows it, and icon buttons move a rule up or down and change the counts at once. A purge band takes a pattern, says how many of the cached paths it would clear ("Would clear 3 of 8 cached paths."), marks each one it matches and records the purge in the page. The last band counts unsaved changes in a status line beside a Shine Button to save them and an outline Button to discard them, and stays pinned to the bottom of the screen. On a phone each rule becomes a card. It's built from Number Input, Native Select, Input, Button, Shine Button and Guides, with hand-built bars and a CSS entrance only. For CDNs, edge platforms and any ordered rule list where order decides the outcome.

FAQ

How does first match wins work here?

Each cached path is given to the first rule, from the top, whose pattern covers it; a star in a pattern stands for any run of characters. The count on each rule is how many of the eight typed paths it was given, so the counts always add up to eight. Move the catch-all rule above the others and it takes every path, and the rules under it read "Shadowed by a rule above it". Moving a rule says where it went in the status line and keeps focus on the button you pressed (the other one when that button has nowhere to go).

What do the bars show?

How long a copy is served, on a log scale fitted to the longest rule, so ten seconds and a week both show. The solid part is the time a copy stays fresh and the lighter part is how long a stale copy may still be served while the cache refreshes it in the background; a rule with no stale window draws only the solid part. The bars are decoration: the same values are in the fields beside them, and the caption under the table says how to read them.

What does Purge do?

It takes the pattern in the field, counts the cached paths it covers that haven't been purged, and marks them in the list as you type. Purge matching, or Enter in the field, records them as purged in this page and says so; it is not part of the unsaved changes, and it refuses, with a message, when nothing matches. Nothing is cleared anywhere.

How do I fill it with my own rules?

Edit the constants at the top. SAVED holds the rules in order, each with a stable id, its pattern, how long a copy stays fresh (ttl and its unit) and its stale window in seconds. UNITS and STALE fill the menus, and CACHED is the list of paths the counts and the purge are worked out against; replace it with the paths your cache really holds.

What stays local, and how do I wire it for real?

All of it: the cached paths are typed, and Save and Purge change only this page. To make it real, send the ordered rules to your edge configuration when saving, ask the edge for the paths a pattern would clear before purging, and call its purge endpoint from the button, showing a failure in the status line. Keep the order the server applies the same as the order shown.

How does it look on a phone, and for a keyboard?

Each rule becomes a card, with its pattern, count and bar on top, then the freshness field and unit, then the stale window beside the move buttons. Every control has its own name that includes the pattern ("Fresh for, /api/", "Move /api/ up"), and the table keeps real headers and a caption for a screen reader on a desktop. The foot stays pinned to the bottom of the screen at every width.

  • Pro

    Rate Limiting Settings

    API and webhooks

    A rate limit you can try: a framed strip replays one client's 24 requests over 10 seconds against the chosen algorithm, limit, window and burst, marking each request allowed or rejected and counting both.

  • Pro

    A matrix of API limits with the plans across and a number field in every cell, a daily capacity worked out under each plan and a guard that stops a higher plan from allowing less than the plan before it.

  • Pro

    Custom Domain Settings

    Domains and delivery

    A custom domain settings panel that leads with what visitors get at each step and walks four stages on a vertical rail: add a domain, add a CNAME and a TXT record with copy buttons, a simulated two-try DNS check and a sample certificate.

  • Pro

    DNS Settings

    Domains and delivery

    A DNS settings panel that leads with a resolver you can ask, then holds the same zone as a filterable records table with TTL and conflict checks and as a zone file parsed as you type, kept in step while it is valid.

  • Pro

    Email Domain Settings

    Domains and delivery

    A sending domain settings panel that leads with what SPF, DKIM and DMARC amount to for your mail, shows the three records as cells with status, host and value to copy, and a DMARC policy select that rewrites its record.

  • Pro

    Environment Variables Settings

    Domains and delivery

    An environment variables settings panel that shows where each variable is set across Production, Preview and Development, counts what is missing, fills a missing value with Copy from, and previews a pasted .env file before it imports.