Rules as the differentiator

A cache without rules is a sledgehammer — every query treated the same, every result held for the same length of time, every user sharing the same view. That works for toy demos and almost nothing else. The Airbrx rules engine is what makes caching usable against real workloads.

Why rules

Real workloads aren't uniform. Aggregate queries on slow-changing dimensions can be cached for an hour without anyone noticing. Live transactional reads against orders can't tolerate even a minute of staleness. PII-bearing queries shouldn't be shared across users; aggregate dashboards absolutely should be. A single TTL across all of that either over-caches (and serves stale or leaky data) or under-caches (and squanders most of the savings).

Rules let you describe each kind of traffic on its own terms. The Gateway evaluates them per-query and decides what to cache, how to key it, and how long to keep it.

Two kinds of rule, both first-class

Most caching products treat invalidation as an afterthought — a knob you reach for when caching has already created a problem. In Airbrx, invalidation rules are peers of cache rules. They share the same matching language; they live in the same rule list; you author them in the same App page.

Treating them as peers means you can express things like "cache aggregates on orders for one hour, but invalidate the whole set immediately when an INSERT lands" — without leaving the rules surface, without waiting for the TTL to expire, without reaching for an external invalidation API.

Conditions and actions

Every rule has the same shape: conditions describe what queries the rule applies to, and actions describe what happens when it matches.

Conditions can match on:

Actions describe what the Gateway should do when the conditions match: cache for a TTL, key the result by user or session, refuse to cache, or mark another rule's results invalid.

The exact JSON shape lives in the rule schema reference, and Ship your first cache rule walks through a worked end-to-end example you can run today.

Priority and matching mode

Rules are evaluated in priority order. Lower priority numbers win, which feels backwards until you internalize it: priority 1 is "most important," priority 100 is "fallback." The first rule whose conditions match determines the action; later rules don't get a chance.

Within a single rule, conditions can be combined two ways. "All" mode is logical AND — every condition has to match. "Either" mode is logical OR — any condition matching is enough. Most rules want "all"; "either" is useful for things like "any of these three sensitive schemas should be excluded from caching."

Predictable cache keys

When a cache rule matches, the Gateway computes a cache key by hashing the elements the rule says are relevant — typically the statement, the tenant, sometimes the user, sometimes the parameter values. The key is deterministic: the same inputs always produce the same key, and the Gateway can compute it without consulting any storage.

That deterministic property is load-bearing. It means hit-or-miss is a single hash computation regardless of how many cached results exist, and it means two services computing the same key for the same query reach the same answer. There's no cache directory to query, no global lock, no "is this entry there yet" race.

It also means cache keys are diagnosable. The request lifecycle exposes the key the Gateway used; if a query you expected to hit cache didn't, you can see exactly which inputs went into the key and figure out what differed.

Cross-rule invalidation

Invalidation rules don't operate on the cache directly — they point at the cache rules whose results they make suspect. When a write matches an invalidation rule, the Gateway records a marker against each named cache rule. The next read against a marked cache rule re-executes against the warehouse and re-caches, even if the rule's TTL hadn't expired.

Two practical knobs sit on top of this:

Where each resource fits

Rules touch all three resources in different ways:

When to reach for the JSON

Most rule changes happen in the App's Rules workshop, where the form takes care of shape and validation. You'll reach for the raw rule JSON when you're scripting bulk changes, importing rules from another tenant, or generating rules from an external system. When that's the right move, the rule schema reference has the field list, types, and validation constraints.

Where to go next

Ready to try it?

Airbrx is in private preview. Create an account and write your first rule in the App.

Create an account