# Rails.cache and problem with model id?

**URL:** <https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664>\
**Category:** Rails\
**Created:** [November 19, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664 "2008-11-19T23:03:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [November 19, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664/1 "2008-11-19T23:03:03Z")

</div>

I have the following:  
MODEL:

def self.get\_tag\_cloud  
Rails.cache.fetch(‘fetish\_tag\_cloud’, :expires\_in =\> 1.hour) do  
find(:all, :conditions =\> [“approved\_for\_tag\_cloud = true”],  
:order  
=\> “LTRIM(name)”)  
end  
end

CONTROLLER:

def index  
@fetishes = Fetish.get\_tag\_cloud  
end

VIEW:

…  
\<% @fetishes.each do |fetish| -%\>

- \<%= link\_to fetish.name, "/fetishes/#{fetish.id}", :class =\> "size#{fetish.tag\_size}"%\>
\<% end -%\> ....

I get the following error:

stack level too deep

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.2/lib/active\_record/attribute\_methods.rb:244:in  
`method_missing' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.2/lib/active_record/attribute_methods.rb:245:in `method\_missing’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.2/lib/active\_record/base.rb:2163:in  
`to_param' (eval):2:in `fetish\_path’  
app/views/fetishes/index.html.erb:22:in  
`_run_erb_47app47views47fetishes47index46html46erb' app/views/fetishes/index.html.erb:21:in `each’  
app/views/fetishes/index.html.erb:21:in  
`\_run\_erb\_47app47views47fetishes47index46html46erb’

* * *

If I do not cache the query it works beautifully… basically when I  
cache  
that query anytime I try to view fetish.id I get a stack level to deep  
error… anyone ever get this problem?

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [November 20, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664/2 "2008-11-20T16:12:12Z")

</div>

More info… the first time when I write to the cache it works  
perfectly fine… the second time around when I am reading from the  
cache the errors start popping up. hmmm…

On Wed, Nov 19, 2008 at 5:08 PM, John K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > find(:all, :conditions => ["approved_for_tag_cloud = true"], :order => "LTRIM(name)")
> > 
> > ```
> > 
> > \<% end -%\>  
> > app/views/fetishes/index.html.erb:21:in `each’  
> > Blog: [http://www.kopanas.com](http://www.kopanas.com)  
> > Conference: [http://www.cusec.net](http://www.cusec.net)  
> > Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [November 20, 2008, 4:16pm UTC](https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664/3 "2008-11-20T16:16:21Z")

</div>

Nobody has ever encountered this problem before?

On Wed, Nov 19, 2008 at 5:09 PM, John K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > ```
> > > @fetishes = Fetish.get_tag_cloud
> > > 
> > > ```
> 
> –  
> John K.  
> removed\_email\_address@domain.invalid
> 
> Blog: [http://www.kopanas.com](http://www.kopanas.com)  
> Conference: [http://www.cusec.net](http://www.cusec.net)  
> Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [November 20, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/rails-cache-and-problem-with-model-id/153664/4 "2008-11-20T16:38:43Z")

</div>

On 20 Nov 2008, at 15:11, John K. wrote:

> Nobody has ever encountered this problem before?

[http://rails.lighthouseapp.com/projects/8994/tickets/785-caching-models-fails-in-development](http://rails.lighthouseapp.com/projects/8994/tickets/785-caching-models-fails-in-development)
