creating a cache in rails

I need to create a small hash of values that persists across requests in Rails. I cannot store this information in the database or filesystem and only want to do it in memory. I was looking for a simple solution to implement this and read somewhere that memcache is pretty much overkill. This app is only running on one server so putting in memory should be just fine. I'm very new to rails and ruby and have attempted to implement a class variable like @@cache in my controller and that didn't work. I've also attempted to create a singleton class (include Singleton) outside of the controller and that didn't work either. Here is the singleton class that I created to cache the information. Any help would be appreciated. Thanks.

This would work as long as you have a *single* app server. As soon as you have two or more then they won't be able to share this information and you have syncing problems... which I'm guessing from below is going to matter to you (for a cached list of states say it wouldn't).

Memcache isn't hard to setup and does exactly what you want -- but keep in mind it's not persistant (meaning if it fills up, it will remove old entries).

Why can't you use the database or /tmp files?

Philip Hallstrom wrote:

Any help would be appreciated. Thanks.

This would work as long as you have a *single* app server. As soon as you have two or more then they won't be able to share this information and you have syncing problems... which I'm guessing from below is going to matter to you (for a cached list of states say it wouldn't).

Memcache isn't hard to setup and does exactly what you want -- but keep in mind it's not persistant (meaning if it fills up, it will remove old entries).

Why can't you use the database or /tmp files?

The code I posted is running in a single app server and isn't working

By single app server do you mean you have *one* mongrel process (or equivelant) or *one* physical server?

for me for some reason. We are taking credit card information and don't want to store it anywhere other than memory. Thanks.

memcache is ram only...

There is this guy who had exactly the same problem and He came up with:

http://boogaloo.rubyforge.org/doc/

with drb its trivial to roll your own caching mechanism.