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

  • SEARCH
  • Home
  • 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 7865441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:05:16+00:00 2026-06-03T00:05:16+00:00

Recently I added a Varnish instance to a Rails application stack. Varnish in it’s

  • 0

Recently I added a Varnish instance to a Rails application stack. Varnish in it’s default configuration can be convinced from caching a certain resource using the Cache-Control Header like so:

Cache-Control: max-age=86400, public=true

I achieved that one using the expires_in statement in my controllers:

def index
  expires_in 24.hours, public: true
  respond_with 'some content'
end

That worked well. What I did not expect is, that the Cache-Control header ALSO affects the browser. That leads to the problem that both – Varnish and my users browser cache a certain resource. The resource is purged from varnish correctly, but the browser does not attempts to request it again unless max-age is reached.

So I wonder wether I should use ‘expires_in’ in combination with Varnish at all? I could filter the Cache-Control header in a Nginx or Apache instance in front of Varnish, but that seems odd.

Can anyone enlighten me?

Regards
Felix

  • 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-06-03T00:05:17+00:00Added an answer on June 3, 2026 at 12:05 am

    That is actually a very good and valid question, and a very common one with reverse proxies.

    The problem is that there’s only one Cache-Control property and it is intended for the client browser (private cache) and/or a proxy server (shared cache). If you don’t want 3rd party proxies to cache your content at all, and want every request to be served by your Varnish (or by your Rails backend), you must send appropriate Cache-Control header from Varnish.

    Modifying Cache-Control header sent by the backend is discussed in detail at https://www.varnish-cache.org/trac/wiki/VCLExampleLongerCaching

    You can approach the solution from two different angles. If you wish to define max-age at your Rails backend, for instance to specify different TTL for different objects, you can use the method described in the link above.

    Another solution is to not send Cache-Control headers at all from the backend, and instead define desirable TTLs for objects in varnish vcl_fetch(). This is the approach we have taken.

    We have a default TTL of 600 seconds in Varnish, and define longer TTLs for pages that are definitely explicitly purged when changes are made. Here’s our current vcl_fetch() definition:

    sub vcl_fetch {
      if (req.http.Host ~ "(forum|discus)") {
        # Forum pages are purged explicitly, so cache them for 48h
        set beresp.ttl = 48h;
      }
    
      if (req.url ~ "^/software/") {
        # Software pages are purged explicitly, so cache them for 48h
        set beresp.ttl = 48h;
      }
    
      if (req.url ~ "^/search/forum_search_results" ) {
        # We don't want forum search results to be cached for longer than 5 minutes
        set beresp.ttl = 300s;
      }
    
      if(req.url == "/robots.txt") {
        # Robots.txt is updated rarely and should be cached for 4 days
        # Purge manually as required
        set beresp.ttl = 96h;
      }
    
      if(beresp.status == 404) {
        # Cache 404 responses for 15 seconds
        set beresp.http.Cache-Control = "max-age=15";
        set beresp.ttl = 15s;
        set beresp.grace = 15s;
      }
    }
    

    In our case we don’t send Cache-Control headers at all from the web backend servers.

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

Sidebar

Related Questions

I recently added devise confirmable module to my rails app. My application runs well
I recently added a feature to a large application written in Delphi (version 2009)
I recently added some url re-writing to my web application and had to added
I've recently added landscape autorotation to my iPhone navigation based application, however I'm having
I recently added a :title column using Rails migration: class AddTitleToMicroposts < ActiveRecord::Migration def
We have recently added AppFabric as a caching option in our project (Windows server
I've recently added ActiveScaffold to an existing Rails project, and the problem I'm having
I recently added namespaces to my rails app. I had a form that will
I recently added Fragments to my applications. For a new application i'll need to
I recently added the line (set-default-font -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1) to my .emacs file. After that find-file-other-window

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.