# Memcache in prod vs dev

**URL:** <https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259>\
**Category:** Rails\
**Created:** [September 1, 2010, 7:28pm UTC](https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259 "2010-09-01T19:28:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 1, 2010, 7:28pm UTC](https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259/1 "2010-09-01T19:28:03Z")

</div>

I am using memcache for caching in my rails app and currently I have a  
dev and a production environment.

I would like to run the dev environment without caching so that I can  
debug more easily but I wanna enable the caching in production  
obviously. I am using github and capistrano for deployment.

Without doing a check at every statement where I can potentially dig  
into the cache, is there any way of handling this more gracefully or  
globally?

if env == ‘dev’ @post = Post.all else //get @post from cache en

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 2, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259/2 "2010-09-02T18:19:49Z")

</div>

Assuming you are using standard page/fragement/action caching you can  
just set

config.action\_controller.perform\_caching = false

in your development environment file. If you are making direct calls  
to Rails.cache you can use a cache store stub in development.

I just did this today for my test environment

Details in my post earlier today

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/b8603c94ac08940a](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/b8603c94ac08940a)

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 2, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259/3 "2010-09-02T17:29:38Z")

</div>

badnaam wrote:

> I am using memcache for caching in my rails app and currently I have a  
> dev and a production environment.
> 
> I would like to run the dev environment without caching so that I can  
> debug more easily but I wanna enable the caching in production  
> obviously. I am using github and capistrano for deployment.
> 
> Without doing a check at every statement where I can potentially dig  
> into the cache, is there any way of handling this more gracefully or  
> globally?
> 
> if env == ‘dev’ @post = Post.all else //get @post from cache en

Rails turns caching off by default in the development environment, if I  
remember correctly. If not, you can certainly turn it off yourself in  
config/environments/development.rb .

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/memcache-in-prod-vs-dev/194259/4 "2010-09-06T16:39:23Z")

</div>

I understand how to turn caching on or off. Well let me explain.

let’s say if I am using memcache and I have a post listing page that  
uses the following method. Now If I want to not use caching in  
development I will have to write this method without the CACHE.fetch?  
So basically, I am doing a if/else in every method do check if it’s  
dev or prod and then either get the collection/fragment from the CACHE  
or not. This seems ugly, wondering if there is a better way.

def get\_all\_post  
CACHE.fetch(“all\_posts”) {Post.all}  
end
