Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Lock Error when nesting ThreadSafe::Cache objects #24

@elspethsoup

Description

@elspethsoup

I see that you cannot nest the usage of ThreadSafe::Cache objects in version 0.3.5 of the gem because there is a single Mutex for all instances of ThreadSafe::Cache. Looking through the git history, I see that this issue has existed since at least 2012, so if you guys don't want to fix it, that makes total sense to me.

Here's a little ruby script that demonstrates the issue.

require 'thread_safe'

outer = ThreadSafe::Cache.new
inner = ThreadSafe::Cache.new

outer.compute("seven") do
  three = inner.compute("three") { 3 } #blows up here
  three + 4
end

The place where the issue comes in for me is with using Rails.cache in conjunction with a ThreadSafe::Cache as the ActiveSupport::Cache seems to use one already under the hood. I'm using Rails v4.2.

I'm planning on switching to Concurrent::Map once I upgrade my project from concurrent-ruby 0.9.2 to 1.0.0 and I can monkey patch until then.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions