Theme Cache 1.2 for Coppermine 1.6.x
====================================

Caches the home page, category pages and album thumbnail pages for visitors
who are not logged in. Based on Theme Cache 1.1 by {ron4mac}.

Meant for hosts that limit MySQL connections: a cached page holds its database
connection for a fraction of the time, and in .htaccess static mode guests
are served without PHP or MySQL at all.


INSTALL / UPGRADE FROM 1.1
--------------------------
1. Upload the "theme_cache" folder to plugins/ (replace the 1.1 files).
2. Create a folder named "cache" in each theme you want cached, e.g.
   themes/curve/cache, and make it writable by the web server.
   (Same as 1.1: an existing cache folder keeps working.)
3. If 1.1 is already installed, replacing the files is enough: your cache
   time is kept and the new settings start at their defaults. Otherwise
   install "Theme Cache" in the plugin manager.
4. Open the plugin's configuration page (plugin manager -> Configure).


WHAT GETS CACHED
----------------
- index.php with no parameters, ?cat=N and ?page=N
- thumbnails.php?album=N (with optional cat, page, sort)
- the meta albums listed in the settings (default: lastup, lastalb, topn,
  toprated). favpics, random, search, lastupby, lastcomby and datebrowse are
  never cached, because they differ per visitor.
- only for visitors who are not logged in, have not entered an album
  password, and only for GET/HEAD requests
- any other parameter in the URL (lang=, theme=, search, file=, uid=, junk
  added by bots ...) means the page is built normally and not cached

The cache key includes language, theme, sort order and the cookie-consent
state, so visitors who picked another language or theme get the right page.

A cached page still starts Coppermine's core (about 8 small queries:
config, plugins, guest group, languages, ban check). The page's own
queries (categories, albums, thumbnails, statistics) are skipped.
Test install: index.php 31 queries uncached, 8 cached (1.1: 19);
album page 18 uncached, 8 cached (1.1: 13). Static mode: 0.


WHEN THE CACHE IS CLEARED
-------------------------
- after an upload, file edit, file delete, comment add/approve/edit
- after any form submitted by an admin or by a user managing their own
  albums (album manager, category manager, config, batch add ...),
  and after delete.php
- when a plugin is disabled or uninstalled in the plugin manager
- the "Clear the whole cache now" button on the config page
- expired pages are removed automatically (checked at most every 15
  minutes), and the number of files is capped at the configured maximum.

When a page expires, one request rebuilds it while other visitors are
still given the old copy (header "X-Theme-Cache: STALE"). This avoids a
burst of identical expensive requests all hitting MySQL at once.

Response header X-Theme-Cache: HIT / STALE shows when PHP served a cached
copy. Last-Modified is sent and If-Modified-Since gets "304 Not Modified".


.HTACCESS STATIC MODE (OPTIONAL)
--------------------------------
Tick "Enable .htaccess static mode" and save. The config page then shows a
block of Apache rules; paste it at the TOP of the .htaccess file in your
Coppermine folder. Needs Apache with mod_rewrite allowed in .htaccess
(most shared hosts). If the site shows "500 Internal Server Error" after
adding the rules, remove them again.

The plugin then also writes plain HTML copies of these URLs, for the default
theme and default language only:
    index.php, index.php?cat=N, index.php?cat=N&page=M,
    thumbnails.php?album=N, thumbnails.php?album=N&page=M
and Apache sends them directly, so no PHP and no database connection is
used for those guest views.

How logged-in users are kept out of static pages: the plugin sets a cookie
named <cookie_name>_stc_nc for anyone whose pages differ from the default
guest view (logged in, another language or theme, a chosen sort order,
album password entered). The rules skip static copies when that cookie is
present. It is set as soon as someone submits the login form.

Limits of static mode (also shown on the config page):
- IP bans and the gallery "offline" switch are not checked for pages Apache
  serves. Switching the gallery offline clears the static copies on the next
  PHP request.
- Users who were already logged in before you enabled static mode may see a
  guest page until they open any other page (a picture, login, profile ...).
- With user integration (bridging to a forum), logins happen outside
  Coppermine, so the cookie is not set at login. Static mode is not
  recommended with bridging.
- With language auto-detection, a first-time visitor may get one or more
  pages in the default language before their own language takes over.
- Static copies are deleted when they expire, but only when some PHP page
  runs (pictures, admin, logged-in users). On a gallery where nothing but
  static pages is ever requested they can stay longer than the set time;
  uploads and admin changes still clear them.
- Regenerate the rules if you move the gallery, change the default theme,
  the cookie name, or the cookie consent setting.

Before uninstalling, remove the rules from .htaccess. (If you forget, the
rules find no static files, so visitors just get the normal pages.)


FILES
-----
codebase.php        the plugin
config.php          configuration page
configuration.php   plugin manager details
lang/english.php    texts
