All questions

Is croct.evaluate fast enough to call on every route change?

Asked by andrei.s on

Aandrei.s

SPA, classifieds site, high navigation frequency. I gate a UI element behind this on every client-side route change:

croct.evaluate("user is returning and session's stats' pageviews > 3")

Works fine. Question is whether calling it per navigation is an intended pattern or an abuse I will pay for at scale. Alternative would be caching the result per session in memory.

average user does 15-20 navigations per session here.

Was this helpful?

1 answer

Ssamw

Per-navigation is the intended pattern, not an abuse. CQL evaluation targets under 20ms and the whole API is built for real-time per-interaction use, so 15-20 calls per session is squarely what it is designed for.

More importantly, your specific condition is one you should NOT cache. It contains session's stats' pageviews, which grows as the user browses. Cache the result on navigation 2 and the user who crosses the threshold on navigation 5 never flips. Real-time evaluation is the feature, caching it defeats the point. Only cache conditions whose inputs genuinely cannot change mid-session.

Two hygiene points for high-frequency calls:

croct.evaluate("user is returning and session's stats' pageviews > 3")    .catch(() => false);

Always attach the .catch so a network hiccup degrades to the default UI instead of an unhandled rejection in your router. And keep queries within the 1-500 character limit, which yours is nowhere near, but it matters if you start composing bigger conditions dynamically.

Was this helpful?
Aandrei.s

The pageviews clause is exactly what I would have gotten wrong, a cached stale false. Keeping it per navigation with the catch.

Still have questions?