Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 320797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:47:12+00:00 2026-05-12T08:47:12+00:00

I’ve got a Rails app that has stopped caching somewhere along the way, and

  • 0

I’ve got a Rails app that has stopped caching somewhere along the way, and I’m not sure which revision along the way might have stopped it from working.

I’m under the impression that page caching, when working properly, should never even hit Rails if it finds the cached file. However, when loading my page and monitoring production.log, it’s hitting both Rails and the DB.

I have a sweeper set up that clears the cache on :create, :update, and :destroy. It works fine, as the /public/cache/index.html file is updated whenever one of those events occurs. I thought at first that it might be because I was using the OutputCompression plugin, but removing that had the same result, so I put it back in. The index.html is there, but .htaccess and Rails ignore it and rebuild the entire page, including rewriting the cached index.html.

Here are the relevant parts of the code (unless I’m missing something):

Controller:

class SecretsController < ApplicationController
  caches_page :index
  cache_sweeper :secret_sweeper, :only => [:create, :update, :destroy]

  # snipped
end

.htaccess:

RewriteEngine On

# Rewrite index to check for cached
RewriteRule ^/$ /cache/index.html [QSA]
RewriteRule ^$ /cache/index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Firebug response headers

Date: Tue, 02 Jun 2009 18:50:36 GMT
Server: Apache/1.3.41 (Unix) mod_fastcgi/2.4.2 PHP/5.2.9 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.8b
Vary: Accept-Encoding
X-Runtime: 0.05637
Etag: "4f3497a74141d1e92ae7a1fe4d5dc1d2"
Cache-Control: private, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 22356
Connection: close
Content-Type: text/html; charset=utf-8
default-style: tms

I’d love to be able to use mod_gzip, but ASmallOrange doesn’t support it, while DreamHost did (before they tripled my price).

Anyway, can anyone shed any light on why Rails is ignoring the cached index.html? I’m assuming it’s something in .htaccess, since it should never touch Rails if it’s working right.

EDIT: The caching problem turned out to be the first slash on the RewriteRules. It wasn’t finding the cached file until I changed them both to “cache/index.html”, and now caching works perfectly.

However, now I do have to remove the OutputCompression calls, because it’s returning the gzipped version of the file with the Content-Type set to “text/html”. Any idea how to get it to send the correct content type for just that file? It’s the only one cached in the entire app.

EDIT AGAIN: Changing the .htaccess to this didn’t help with the gzip problem:

RewriteRule ^/$ cache/index.html [QSA,T=application/x-gzip]
RewriteRule ^$ cache/index.html [QSA,T=application/x-gzip]

It still shows up as the text representation of a zip file (i.e. gibberish), unless compression is disabled. Caching works perfectly, though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:47:13+00:00Added an answer on May 12, 2026 at 8:47 am

    Finally figured out the problem(s), and my site is live once again after 10 weeks of downtime. Once I got it to load the cache file, I found another problem in that the OutputCompression plugin was compressing the file to a .gz file, but Rails was saving it as .html, and Apache was serving that as text/html, which resulted in gibberish.

    The fixes that solved my problem:

    In .htaccess:

    AddEncoding x-gzip .gz
    AddType text/html .gz
    
    RewriteRule ^/$ cache/index.gz [QSA]
    RewriteRule ^$ cache/index.gz [QSA]
    

    In config/environments.rb:

    ActionController::Base.page_cache_extension = ".gz"
    

    The Ruby code makes the “caches” directive save as “cache/index.gz” instead of “cache/index.html”. AddEncoding tells it not to serve it as html, but by itself will just display the page source, since it defaults to a Content-Type of “text/plain”. AddType changes things so that .gz files are served as “text/html”, causing proper display.

    This probably won’t work for everyone, but since I don’t serve .gz files anywhere on the site, and the front page is the only one cached, this works perfectly for me.

    Thanks to everyone for the help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.