Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bypassing record_cache when selecting rows with lock #2

Closed
dhruvg opened this issue Nov 1, 2011 · 2 comments
Closed

bypassing record_cache when selecting rows with lock #2

dhruvg opened this issue Nov 1, 2011 · 2 comments

Comments

@dhruvg
Copy link

dhruvg commented Nov 1, 2011

Hi,
Thanks for sharing record-cache, it is pretty solid.

I am tinkering around with it and I notice that record cache seems to hit the cache even when I want to retrieve rows with a lock. Example:

transaction do
Item.lock("lock in share mode").where(:conditions).each do |i|
...
end
end

When I look at my SQL logs, I only see:
BEGIN
COMMIT

The actual select query is not there. When I disable record_cache and do the same thing again, the select query is there as expected. So it makes me believe that record cache is retrieving from cache even though I want to lock the rows in the db.

What would be the best way to get around this, so for any lock selects, record-cache is bypassed?

Thanks!

@orslumen
Copy link
Owner

orslumen commented Nov 1, 2011

Thanks for reporting the issue.

To temporarily disable fetching records from the cache, you can use the following construct:

RecordCache::Base.without_record_cache do
  transaction do
    Item.lock("...").where...
  end
end

And I just committed a more permanent fix that will automatically bypass any lock-select as suggested. This will be included in the next version.

PS. Instead of looking in the SQL logs, you can also switch on DEBUG logging (config.log_level = :debug in development.rb) to get more information on record-cache hits and misses.

@dhruvg
Copy link
Author

dhruvg commented Nov 1, 2011

Fantastic, I appreciate the quick response. Thanks for making this!

@dhruvg dhruvg closed this as completed Nov 1, 2011
fmauz pushed a commit to inventae/model-cache that referenced this issue Apr 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants