Thanks for your reply Devlin. I literally just solved it as you posted :)
Your solution wouldn't work in my case as I don't want to have to remember what the last number I used was. I'm using it to rotate between static content servers.
It would appear that if you return an object it doesn't get cached. So I just returned the instance of my singleton class and then added the function XML_val (which is required of you want to use the dot notation in the .ss file) and Robert's your mothers brother.
For those out there having a similar problem, my code is below.
.ss file
<img src="$staticSites().nextServer()/themes/default/img1.png">
<img src="$staticSites().nextServer()/themes/default/img2.png">
<img src="$staticSites().nextServer()/themes/default/img3.png">
My static server class
<?php
final class StaticServers {
private $servers = array();
private static $inst = null;
private $pos = 0;
public static function instance()
{
if ( self::$inst === null ) self::$inst = new StaticServers();
return self::$inst;
}
public function nextServer()
{
return $this->servers[ $this->nextPos() ];
}
public function XML_val( $field, $arguments = null, $cache = false )
{
switch( $field )
{
case "nextServer":
return $this->nextServer();
break;
}
}
private function nextPos()
{
$currentPos = $this->pos;
$this->pos = $this->pos < sizeof( $this->servers ) - 1 ? $this->pos + 1 : 0;
return $currentPos;
}
private function __construct()
{
// TODO: Pull these from the database
$this->servers = array(
'static01.mySite.co.uk',
'static02.mySite.co.uk',
'static03.mySite.co.uk',
'static04.mySite.co.uk',
'static05.mySite.co.uk'
);
}
}
And in my Page_Controller class
public function staticSites()
{
$inst = StaticServers::instance();
return $inst;
}
Edit: I then added an override for the content so I could put ##static## in the html through the CMS and it would be replaced with the static servers.
public function Content()
{
return preg_replace_callback(
'/##STATIC##/siU',
'self::nextServer',
$this->Content
);
}
public function nextServer($matches)
{
return StaticServers::instance()->nextServer();
}