Prompt

how to set TTL for feature flag caching

Technology / Cloud Infrastructure1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

Setting a TTL for feature flag caching depends on where the flags are cached and which feature flag system/language you’re using. The general idea is:

  1. Store flags in memory or a cache
  2. Attach an expiration time (TTL)
  3. Refresh from the flag provider when expired

Common approaches

1) In-memory cache with TTL

If you’re caching feature flags yourself, set a timestamp and invalidate after TTL.

Example logic:

  • Cache flags at t = now
  • TTL = 60 seconds
  • If now - cached_at > 60s, fetch fresh flags

Pseudocode:

cache = {"flags": None, "cached_at": 0}
TTL = 60

def get_flags():
    if cache["flags"] is None or time.time() - cache["cached_at"] > TTL:
        cache["flags"] = fetch_flags_from_server()
        cache["cached_at"] = time.time()
    return cache["flags"]

2) Redis or distributed cache TTL

If you use Redis, set the key expiry directly.

Example (Redis):

SET feature_flags '{"new_ui": true}' EX 60

Or in code:

redis.set("feature_flags", flags_json, ex=60)

3) SDK-managed caching

Many feature flag providers already cache flags internally and offer configuration for refresh intervals.

Examples:

  • LaunchDarkly: streaming/polling config, cache is typically managed by SDK
  • Unleash: refreshInterval / polling interval
  • Flagsmith: client cache settings / polling interval
  • ConfigCat: cache refresh mode and TTL-like settings

In these cases, you usually configure:

  • Polling interval
  • Cache refresh interval
  • Stale-while-revalidate behavior

What TTL should you choose?

Typical values:

  • 10–30 seconds for near-real-time changes
  • 1–5 minutes for less critical flags
  • Longer if you want fewer network calls and can tolerate delay

Best practice

If flags control sensitive behavior, use:

  • Short TTL
  • Background refresh
  • Fallback/default values
  • Cache invalidation on config updates if supported

If you tell me which language/framework and which feature flag service you’re using, I can give you the exact code/config.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.