tags:

views:

109

answers:

1

As I have posted before also,I am developing a site in two languages done in CakePHP. Now the latest problem I am facing in my application is that the application is not sharing the Cache values between the Main Domain and the Subdomain.Please help me out of this mess...!!!

Thanks in advance.

+2  A: 

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:

  1. Create my_view.php (or whatever) in app/views
  2. Content:

    class MyView extends View { }

  3. 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

  4. 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.

rscherer
could you tell me how can I add subdomain while reading and writing Cache.How can I add subdomain in this Cache::read() and Cache::write()
Nishant Shrivastava
You just prefix the cache key with your subdomain identifier, i.e.Cache::write( CURRENT_SUBDOMAIN . '_recent_posts', $data, '1 day' );
rscherer