Skip to content

RedisCacheStore#delete_matched doesn't play well with local cache #38627

@ojab

Description

@ojab

Steps to reproduce

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails"
  gem 'redis'
end

require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"

class BugTest < Minitest::Test
  def test_with_local_cache
    client = ActiveSupport::Cache::RedisCacheStore.new

    client.with_local_cache do
      client.write('my_key#123', 'xxx')
      client.delete_matched('my_key#*')

      # Passes
      assert client.send(:bypass_local_cache) { client.read('my_key#123') }.nil?

      # Fails
      assert client.read('my_key#123').nil?
    end
  end
end

Expected behavior

Test should pass or at least rails should provide a way to handle that case without hacky #send(:bypass_cache) { }

Actual behavior

Test fails, we're reading stale value from local cache.

System configuration

Rails version: 6 & master

Ruby version: 2.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions