Development

#6715 (symfony creates unexpected page cache when requested by HEAD method.)

You must first sign up to be able to contribute.

Ticket #6715 (closed defect: fixed)

Opened 9 months ago

Last modified 1 month ago

symfony creates unexpected page cache when requested by HEAD method.

Reported by: GOTTi Assigned to: Kris.Wallsmith
Priority: major Milestone: 1.3.0 alpha2
Component: cache Version: 1.2.7
Keywords: cache HEAD request sfWebResponse Cc:
Qualification: Unreviewed

Description

Situation

Enabling page cache setting as follows:

-settings.yml

prod:
  .settings:
    cache:  on

-cache.yml

enabled: on
with_layout: true
lifetime: 300   # example value

When a page whose page cache has been expired is requested by HEAD method, symfony creates a new page cache which has a property 'headerOnly = true', because symfony always sets this property of the sfWebResponse to true when requested by HEAD method. (see cache/frontend/prod/config/config_factories.yml.php)

After this, symfony will not return the body of that cached page for the subsequent GET request because the cached sfWebResponse object has a property 'headerOnly = true'.

Proposal

Symfony should create page caches with a property 'headerOnly = false' even if requested by HEAD method.

Related

Reference of the sfWebResponse object should be updated after reading page cache http://trac.symfony-project.org/ticket/6633

Change History

07/26/09 16:22:16 changed by Kris.Wallsmith

  • owner changed from fabien to Kris.Wallsmith.
  • milestone set to 1.2.9.

09/13/09 23:46:07 changed by FabianLange

  • milestone deleted.

kris did you plan on working on this for 1.2.9? I was about to release it, so I unset the milestone.

10/12/09 01:28:42 changed by Kris.Wallsmith

  • status changed from new to closed.
  • resolution set to fixed.
  • milestone set to 1.3.0 alpha2.

This has been addressed in the 1.3 branch.

02/21/10 23:54:55 changed by mikey

This is a workaround for those using 1.2.

- lib/headCacheFilter.class.php

<?php

/**
 * Disable the cache for HEAD requests
 */
class headCacheFilter extends sfFilter
{
    public function execute($filterChain)
    {
        $context = $this->getContext();

        if($context->getRequest()->getMethod() == sfWebRequest::HEAD) {
            sfConfig::set('sf_cache', false);
        }

        // Execute next filter
        $filterChain->execute();
    }
}

- filters.yml

rendering: ~
security:  ~

head_cache_filter:
  class: headCacheFilter

cache:     ~
common:    ~
execution: ~

It took me quite a while to determine for sure that this was a bug with symfony as this post doesn't rank well in search engines. Basically if you start getting blank pages in your app and you have caching turned on for actions, including the layout, it's probably as a result of this bug.

I'm not sure what is sending HEAD requests so often, possibly web crawlers.

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.