There are 3 problems connected to this.
Data you're caching manually by using Cache::read() and Cache::write()
Just use a prefix for each subdomain when using the methods.
Element caching
you can solve this "almost" elegantly by following these steps:
- Create my_view.php (or whatever) in app/views
Content:
class MyView extends View {
}
Search for view.php in the Cake Core and copy the element() method to your newly created class. Add your subdomain prefix in the part where the caching happens
In your AppController::beforeFilter() write
$this->view = 'MyView';
Now you have control over the CakePHP view layer. You have just overridden the element method.
Alternatively to this approach (if your codebase isn't already using elements extensively) you could just create a helper with a method, that takes the same arguments as the View::element() method, add the subdomain key to the cache options and call the orginal element() method.
Full Page Caching
This is a tricky one. The full page caching happens in the dispatch() method before you have any possibility to modify the behavior. The second problem is, that CakePHP uses the relative URL of the page to cache it. The relative URLs are most likely identical under your different subdomains.
I think the simplest approach here is to create a Dispatcher class, which extends the original dispatcher. Override the cached() method and implement your desired behavior, like the prefixes. Then in your app/webroot/index.php you need to change this line
$Dispatcher = new Dispatcher();
...to your new class name.