Skip to content

Trait data ignored due to cache key not including traits #238

@adamvialpando

Description

@adamvialpando

Trait data is seemingly being ignored in identity evaluations. Likely root cause is the Node.js SDK cache key not including traits, which can cause different trait sets to return the same cached evaluation result.

Problem description

Trait data is “seemingly getting ignored” during evaluations. https://github.com/Flagsmith/flagsmith-nodejs-client/blob/main/sdk/index.ts#L223

Likely root cause

The cache key currently does not incorporate trait values. If the same identity (or request context) is evaluated with different traits, the SDK may return a previously cached result that was computed for a different trait set.

Technical notes / impact

•	The SDK supports external cache implementations (for example Redis) via the cache option in the Flagsmith constructor.
•	Including traits in the cache key will change the key format and cache behavior.
•	For Redis or any shared backing store, changing the key format is likely a breaking change because existing cache entries become unreachable under the new format (and any custom tooling that expects the old key format may break).

Proposed directions (for evaluation)

Option A (backward compatible default)

Add a constructor option, for example:
• includeTraitsInCacheKey: boolean (default false)

When enabled:
• Cache key incorporates a stable serialization of traits (and trait order is normalized)
• Existing users keep current behavior unless they opt in

Option B (intentional breaking change)

Always include traits in the cache key by default.
• Would require a major version release
• Requires explicit migration guidance in release notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions