Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my scope getting cached?

I have a scope that looks as follows:

scope :top, order('score DESC')

It's used as follows in my controller:

def top
  @users = User.top
  render "list"
end

Now, it seems that this scope is getting cached for no reason at all. If I load the top page, add a user and reload it, the user does not appear in the list.

If I do this however:

def top
  @users = User.order('score DESC')
  render "list"
end

The results don't get cached. What is happening here? I'm using Ruby 2.0.0 and Rails 4.0.0

like image 983
BvdBijl Avatar asked Mar 23 '23 22:03

BvdBijl


1 Answers

I think if you use a lambda, then it should not get cached:

scope :top, lambda { order('score DESC') }

But then again, I'm not that familiar with the new Rails 4 scope caching.

like image 143
Christoph Eicke Avatar answered Mar 31 '23 23:03

Christoph Eicke