OK, this is 1 possible solution... my code is perhaps a little clunky. Feel free to improve on it.
This caches for specific referrers... I've used frames in my original version to retain the integrity of the URL. If there is a better way of doing this, I'm all ears.
So if you put this in your displayimage.php file after "require('include/init.inc.php');" you should at least have an emergency incase of the dreaded "digg effect"
$sites = array('digg.com', 'slashdot.org', 'reddit.com', 'stumbleupon.com', 'engadget.com');
if(isset($_SERVER['HTTP_REFERER'])) {
$url = $_SERVER['HTTP_REFERER'];
$url = parse_url($url);
$spliturl = explode(".", $url['host']);
$lastpiece = count($spliturl);
$realurl = $spliturl[$lastpiece-2].".".$spliturl[$lastpiece-1];
if(in_array($realurl, $sites)) {
header('Location: http://'.$_SERVER['HTTP_HOST'].'.nyud.net:8080'.$_SERVER['REQUEST_URI']);
exit();
}
}
This will redirect ALL referrals from those domains to the cache. This may not be what you want, but will help you in a pinch.
To improve on this: Work out the intervals between page visits and if they fall under a certain level, you redirect to your cache... You'll need an "expiry" variable too because once it's reading from the cache, new intervals aren't being recorded.
(though what you can do is replace the "header" part of the above code with a frameset - to retain the URL integrity - and additionally in the upper frame you can record visits etc to avoid the expiry variable)
That way ONLY referrals from portal sites get redirected to the cache, and ONLY if the site is being accessed greater than X number of times a minute.
Add in a !USER_ID in there too and your registered users will never be pushed to a cache...
My version of the interval counter works, but I'm not 100% sure about it's quality yet so I won't post it here.