Rails 3 refuses to clear the cache

Hello,

I’ve recently migrated my application to Rails 3, and I encounter
problems
with the new system of SQL-caching.

I have a ‘category’ action on my PostsController that I access through a
standard :controller/:action/:id route (
www.my_app.net/posts/category/something), and runs a query to find posts
tagged with my parameter using the plugin
acts_as_taggable_on_steroids : @posts
= Post.find_tagged_with(params[:id])

When I restart the server, the query looks like this in my logs :
Post Load (0.2ms) SELECT DISTINCT medias.* FROM medias INNER JOIN
taggings medias_taggings ON medias_taggings.taggable_id = medias.id AND
medias_taggings.taggable_type = ‘Media’ INNER JOIN tags medias_tags ON
medias_tags.id = medias_taggings.tag_id WHERE medias.type IN
(‘Post’)
AND ((medias_tags.name LIKE ‘something’))

… which is perfectly correct.
But when I actualize the page, the query is loaded from cache without
its
parameters and looks like this in the logs :
Post Load (0.7ms) SELECT medias.* FROM medias WHERE medias.type
IN
(‘Post’)

… so I get many results that aren’t correct.
I’ve seen people getting around this problem with the ‘uncached’ block :
Post.uncached do
@posts = Post.find_tagged_with(params[:id])
end

This solution doesn’t work on my application, I still get the correct
result only on the first page load. I even tried to force the query by
calling Rails.logger.debug @posts inside the block, to no avail.
I’ve read that appending ‘.all’ to the call can force the query too, but
find_tagged_with returns an Array, not a Relation, and ‘.all’ isn’t
defined
on Arrays.

What am i missing ? Don’t hesitate to ask if I’m unclear, as I’m not a
native English speaker.

Thank you for your help
Cyril

Hello

For your information, I found a solution to my problem : I removed my
plugin acts_as_taggable_on_steroids and installed acts_as_taggable_on,
which is fully functionnal under Rails 3, and doesn’t have the
apparently-not-so-well-known cache problem of the other one.

Cyril

2012/1/19 Cyril L. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs