# Cached instance variables in ApplicationController in Rails 2.3.5?

**URL:** <https://www.ruby-forum.com/t/cached-instance-variables-in-applicationcontroller-in-rails-2-3-5/181944>\
**Category:** Rails\
**Created:** [January 20, 2010, 3:24pm UTC](https://www.ruby-forum.com/t/cached-instance-variables-in-applicationcontroller-in-rails-2-3-5/181944 "2010-01-20T15:24:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@spike](https://www.ruby-forum.com/u/spike)\
**Post date:** [January 20, 2010, 3:24pm UTC](https://www.ruby-forum.com/t/cached-instance-variables-in-applicationcontroller-in-rails-2-3-5/181944/1 "2010-01-20T15:24:09Z")

</div>

Hi there, I’ve noticed a strange problem in my app that seems to only  
occur under passenger when passenger is restarted for a few minutes:

As most people do, I have cached regularly called methods in  
ApplicationController like so:

def context  
return @context if @context

```
case request.path
when /^\/admin/
  :admin
when /^\/manage/
  @context = :manage
else
  @context = nil
end

```

end

It’s a normal pattern, return @context if that exists, otherwise  
calculate it based upon the URL. I’d expect the normal behaviour to be  
that this gets calculated once per request the first time context is  
called, and then it would return @context from then on.

The problem is that it seems like these instance variables are leaking  
between requests. I get errors relating to @context still being :admin  
even though the request path isn’t an admin path. The only reason for  
this seems to be that the variables are being kept around for the next  
request. The problem seems to go away after passenger has been running  
for a few minutes.

Since this problem seems quite ethereal and hard to pin down I thought  
I’d post this here and see if anyone else has had any problems like  
this?

Looking forward to hearing from you 🙂

Cheers,

Brendon
