Cache page based on cookie value and URL I am working on a site that is multi-lingual as well as multi-country. This means that pages will show content differently depending on a country cookie that is set when the user first visits the site. I used taxonomy tid's for the cookie's value, so there was no issue with case sensitivity, etc. 

The problem is that Drupal's cache_page table indexes content by URL only, so users with different countries but the same URL all get the same content. I was able to get the effect I wanted just by modifying the mod_rewrite implementation:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !(cid)
RewriteCond %{HTTP_COOKIE} (?:^|;\s*)country=([^;]*)
RewriteRule ^(.*)$ $1?cid=%1&amp;%{QUERY_STRING} [L,R=302]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_COOKIE} (?:^|;\s*)country=([^;]*)
RewriteRule ^$ /?cid=%1 [L,R=302]

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


I did have to disable the ExpiresDefault directive, as it was causing the browser to remember old content when the user switches countries. 

The resulting cid's in the cache_page table look like this:

http://example.com/pagename?cid=98
http://example.com/pagename?cid=256


This post isn't so much of a "help me I'm stuck" but a "I had this problem, and here's how I solved it. Can you think of a better way to do this?"
You can do it without .htaccess rules.

Drupal core cache; modify in your settings.php file (apache only). From http://drupal.org/node/361832#comment-4204294

&lt;?php
// Check if cookie is set.
if (!empty($_COOKIE['my_cookie'])) {
  // Add cookie value to page cache id.
  $_SERVER['REQUEST_URI'] .= '#' . $_COOKIE['my_cookie'];

}
// Disable page cache if cookie not set so your magic code can set the cookie.
else {
  $conf['cache'] = CACHE_DISABLED;
}
?&gt;


Memcache
http://drupal.org/node/942914#comment-4477150