Skip to content

Fragile caching mechanism #735

Description

@mochetts

Describe the bug
Split caching system isn't thread / process safe. When the request ends, the cache remains set in the process.

This is due to Split using class instance variables to store the cache.

In a scenario in which you're using Puma with multiple processes handling requests, this is not ideal.

If one process removes or resets an experiment, the cache only gets reset in a single process. Not in all the processes having the cached values.

To Reproduce
Using puma, Split with cache enabled, and 2 browser windows:

  1. Run two requests simultaneously in two windows that query the same experiment.
  2. Both should cache the same variant
  3. Now set the a different variant as the winner in the split console
  4. Reload both windows
  5. You should see one window still running the non-winner variant.

Suggestions

  • Add an option to make split cache request scoped (same as rails CurrentAttributes). So the cache only lives throughout the lifecycle of a request.
  • Add a way to use CurrentAttributes for the caching mechanism instead of the current class instance variable method.

Activity

  1. andrehjr commented on May 17, 2025

    @andrehjr
    Member

    Thanks for bringing this up! Yes, the local caching mechanism should work over a single request lifecycle. I think we can improve this by hooking the cache onto the Split::Helper instead.

    The ideal solution would be to solve what's causing the performance impact. The number of Redis calls made per single request. But that needs a lot more work.

  2. mochetts commented on Jun 21, 2025

    @mochetts
    Author

    We solved the performance issue we were having not by using Split's built in cache but by using a request cache such as rails "CurrentAttributes". Maybe it's worthy to implement/use a request cache instead.

  3. snaka commented on Feb 14, 2026

    @snaka
    Contributor

    Thank you for this great gem. We've been using Split with caching enabled for about 3 years to address performance issues. Recently, we discovered problems when setting a winner from the dashboard, which led us to this issue.

    This cache invalidation problem is serious and can cause production incidents. I've submitted a PR #743 to add a warning to the README to help prevent others from encountering the same issues.

  4. andrehjr commented on Feb 14, 2026

    @andrehjr
    Member

    Thanks, and sorry for that problem.

    My plan is to remove the need for this cache at all. #742 removed most of the redis requests that made the performance hit. Still need to do some testing, but after that, I'll release a new version disabling the cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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