﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15626	Cache middleware doesnt work with pages contain google analytics script	homeip127@…	nobody	"How it appears:
Every request page is taken from cache (cache hits rate increasing), but then it is generated again and put into cache what causes growth of memory occupied by cache.

How to reproduce:
1. Setup cache settings:

{{{
CACHE_BACKEND = 'locmem://'
# or
CACHE_BACKEND = 'memcached://localhost:9450'

CACHE_MIDDLEWARE_SECONDS = 60

MIDDLEWARE_CLASSES = (
	'django.middleware.cache.UpdateCacheMiddleware',
	'django.middleware.common.CommonMiddleware',
	'django.contrib.sessions.middleware.SessionMiddleware',
 	'django.middleware.csrf.CsrfViewMiddleware',
	'django.middleware.http.ConditionalGetMiddleware',
	'django.middleware.gzip.GZipMiddleware', 
	'django.contrib.auth.middleware.AuthenticationMiddleware',
	'django.contrib.messages.middleware.MessageMiddleware',
	'django.middleware.cache.FetchFromCacheMiddleware',
)

}}}

now cache will work as expected 
(First response updates cache backend and return 200 (ok), then 304 (not modified) every request during 1 minute)

2. Now install Google analytics script into template.

{{{
<script type=""text/javascript"">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-9']);
  _gaq.push(['_setDomainName', '.domain.com']);
  _gaq.push(['_trackPageview']);

  (function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
}}}


Page must be open with browser that supports JS and local cache turned off.

Now every request hits cache, than view, database, updates cache and returns response.
in response http headers:
{{{
Etag is changing everytime (but content of page is not changed)
Last-Modified sets to current server time
Expires sets to current time + max age

Conditional requests If-Not-Modified-Since  and If-None-Match are always returning 200 OK response.
}}}

Next, if turn off JS in browser (for example install NoScript in Firefox) cache works fine, conditional requests get 304. Found this bug in Firefox, Opera, Chrome. "	Bug	closed	Core (Cache system)	1.2	Normal	duplicate			Unreviewed	0	0	1	0	0	0
