Session variables and page cache
On the other answer, the page cache is bypassed on the first hit. Subsequent hits do hit the page cache because the cookie will be set then.

To answer your question, have some client side javascript that sets a cookie called gallery_list_mode. If no selection is made, set it to 0 or delete it. If user selected thumbs, have the javascript set the gallery_list_mode cookie to thumbs. Then inside of your settings.php drop this in

&lt;?php
// Check if cookie is set and user is on a gallery page.
if (!empty($_COOKIE['gallery_list_mode']) &amp;&amp; $_SERVER['REQUEST_URI'] == '/gallery') {
  $ok_list = array(
    'thumbs',
  );
  if (in_array($_COOKIE['gallery_list_mode', $ok_list)) {
    // Add cookie value to page cache id.
    $_SERVER['REQUEST_URI'] .= '?list_mode=' . $_COOKIE['gallery_list_mode'];

    // This line might be needed.
    //$_GET['q'] .= '?list_mode=' . $_COOKIE['gallery_list_mode'];
  }
}
?&gt;


This will make http://domain.com/gallery point to the cache entry for http://domain.com/gallery?list_mode=thumbs if the gallery_list_mode cookie is set to thumbs.

As a security feature you should make sure to only accept values for gallery_list_mode that you want. That is what the $ok_list array is for.