# Caching issue? Method not executed every time

**URL:** <https://www.ruby-forum.com/t/caching-issue-method-not-executed-every-time/124609>\
**Category:** Rails\
**Created:** [December 31, 2007, 12:10am UTC](https://www.ruby-forum.com/t/caching-issue-method-not-executed-every-time/124609 "2007-12-31T00:10:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [December 31, 2007, 12:10am UTC](https://www.ruby-forum.com/t/caching-issue-method-not-executed-every-time/124609/1 "2007-12-31T00:10:52Z")

</div>

Hi,

I´m using the Lightning-Fast Javascript Autocompletion recipe from  
Rails Recipes.

When I add or remove users in the contact list, changes are  
immediately reflected in the conacts\_for\_lookup js array. Indicating  
that both the javascript and method is executed when reloading  
\_send.rhtml  
But after a while, the js array is empty:  
var contacts = new Array(0);  
Is there a caching issue, causing the method not to be executed every  
time?  
If I logout and in again, the array is back.

I´m running in development environment.

views/sms/\_send.rhtml

contacts\_controller.rb:  
def contacts\_for\_lookup  
@contacts = Contact.find(:all,  
:conditions =\> “company =  
‘#{session[:user\_number]}’”)  
headers[‘content-type’] = ‘text/javascript’  
render :layout =\> false  
end

contacts\_for\_lookup.js  
var contacts = new Array(\<%= @contacts.size %\>);

\<% @contacts.each\_with\_index do |contact, index| %\>  
contacts[\<%= index %\>] = “\<%= contact.name %\>”;  
\<% end %\>

Any tips or hints are highly appreciated! 🙂

Regards,  
Martin S.
