From 68e6405acad12b77bf382601b0cf836db45a2f65 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Tue, 7 May 2013 17:32:43 +1000
Subject: [PATCH] redis rack cache was crazy, it was just storing stuff in
 redis FOREVER, added a PR to fix, forked to my repo, sourcing a sane version

---
 Gemfile                              |  4 +++-
 Gemfile.lock                         | 13 +++++++++----
 config/initializers/99-rack-cache.rb |  4 ++++
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/Gemfile b/Gemfile
index d5d81356d..4cdcb86db 100644
--- a/Gemfile
+++ b/Gemfile
@@ -134,7 +134,9 @@ gem 'lru_redux'
 gem 'rack-mini-profiler', require: false  # require: false #, git: 'git://github.com/SamSaffron/MiniProfiler'
 
 # used for caching, optional
-gem 'redis-rack-cache', require: false
+# redis-rack-cache is missing a sane expiry policy, it hogs redis
+# https://github.com/jodosha/redis-store/pull/183
+gem 'redis-rack-cache', :git => 'git@github.com:SamSaffron/redis-rack-cache.git', require: false
 gem 'rack-cache', require: false
 
 gem 'rack-cors', require: false
diff --git a/Gemfile.lock b/Gemfile.lock
index 3532e0c3d..4b43175ba 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -46,6 +46,14 @@ GIT
       activerecord (>= 3.0.0)
       activesupport (>= 3.0.0)
 
+GIT
+  remote: git@github.com:SamSaffron/redis-rack-cache.git
+  revision: 379ef30e31d4e185cb1d7f8badca0cc06403eba2
+  specs:
+    redis-rack-cache (1.2.1)
+      rack-cache (~> 1.2)
+      redis-store (~> 1.1.0)
+
 GIT
   remote: https://github.com/rails-api/active_model_serializers.git
   revision: fe84e0ad5268f1439123fd9a1f9fd12e25a54cd3
@@ -350,9 +358,6 @@ GEM
     redis-rack (1.4.2)
       rack (~> 1.4.1)
       redis-store (~> 1.1.0)
-    redis-rack-cache (1.2.1)
-      rack-cache (~> 1.2)
-      redis-store (~> 1.1.0)
     redis-rails (3.2.3)
       redis-actionpack (~> 3.2.3)
       redis-activesupport (~> 3.2.3)
@@ -504,7 +509,7 @@ DEPENDENCIES
   rb-inotify (~> 0.9)
   redcarpet
   redis
-  redis-rack-cache
+  redis-rack-cache!
   redis-rails
   rest-client
   rinku
diff --git a/config/initializers/99-rack-cache.rb b/config/initializers/99-rack-cache.rb
index 292d310d0..822d1e328 100644
--- a/config/initializers/99-rack-cache.rb
+++ b/config/initializers/99-rack-cache.rb
@@ -2,6 +2,10 @@ if Rails.configuration.respond_to?(:enable_rack_cache) && Rails.configuration.en
   require 'rack-cache'
   require 'redis-rack-cache'
 
+  # by default we will cache up to 3 minutes in redis, if you want to cut down on redis usage
+  #  cut down this number
+  RedisRackCache.max_cache_seconds = 60 * 3
+
   url = DiscourseRedis.url
 
   class Rack::Cache::Discourse < Rack::Cache::Context