Welcome Guest, Not a member yet? Register   Sign In
Cache & Multi-domains
#1

[eluser]Rwkzejedi[/eluser]
Hi community,

I use CI.2 for a multilingual website.

Actually, I have some slow-down when I'm loading pages.

I think it's time to use cache... But the native cache of CI cache "too much".

I have 3 name domain pointing in the same application. Each name domain for a language.
But... with the native cache... when I switch language, He continues to read the old language cached...

So I try to use 3 differents cache path... one for each domain.
I create 3 subfolders in "application/cache (chmoded to 777) ...

But nothing happens... No files are written in the different folders. Here is my code

Code:
if(preg_match('#my_site.fr#isu',$_SERVER['HTTP_HOST']))
  {
   $requested_lang_for_domain = 'my_site.fr';
   define('ORDER_ADS_COUNTRY', 8);
   //define the cache folder
   $this->config->set_item('cache_path','/application/cache/fr/');
  }
  elseif(preg_match('#my_site.es#isu',$_SERVER['HTTP_HOST']))
  {
   $requested_lang_for_domain = 'my_site.es';
   define('ORDER_ADS_COUNTRY', 6);
   //define the cache folder
   $this->config->set_item('cache_path','/application/cache/es/');
  }
  else
  {
   $requested_lang_for_domain = 'my_site.com';
   //define the cache folder
   $this->config->set_item('cache_path','/application/cache/en/');
  }
  
  //now we load the domain info with lang
  $lang = $this->langue_model->get_lang($requested_lang_for_domain);
  
  //change base url
  $this->config->set_item('base_url','http://www.'.$requested_lang_for_domain);
  
  //cache during 5 minutes
  $this->output->cache(5);

Do you have an idea ?
Do the native cache of CI works with dynamics datas ? I have an account system. If I login in the website, do my personnal datas are loaded or it's those on the cache ? (Hope it's mine)

Sorry for my bad english, it's not my native language.

Sincerely
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

The '.' in your regular expressions need escaping:
Code:
if (preg_match('#my_site\.fr#i', $_SERVER['HTTP_HOST'])) {

I would suggest that you use strpos instead:
Code:
if (strpos($_SERVER['HTTP_HOST'], 'my_site.fr') !== FALSE) {

However, I'm not sure that this is your problem.

Where are you loading your language files? Have you made sure your cache directory is writable?

I would suggest you get it working correctly without caching, and then you can start caching things.
#3

[eluser]Rwkzejedi[/eluser]
Actually, I'm sure that the cache folder is writtable because at begin, I use the output class and the caching method and it works...

But since I have added the subfolders fr / en and es in the application/cache ... it doesn't work. It's like the
Code:
$this->config->set_item('cache_path','/application/cache/es/');
wasn't use...

It's like I can't rewrite the path of cache on fly.

Thank you for the tip of strpos, I update my code.

#4

[eluser]TheFuzzy0ne[/eluser]
You're absolutely correct. It looks like the cache library sets it's path as soon as it's instantiated, so any changes you make after that have no effect.

You may need to move this back to your index.php file, or config.php. Put some logic in there that will set the right locale and config variables before CodeIgniter loads the configuration.
#5

[eluser]Rwkzejedi[/eluser]
I set a part of this code on the config.php ... but nothing change.

So sad T__T
#6

[eluser]TheFuzzy0ne[/eluser]
Let's see what you have in your config file. Smile
#7

[eluser]rana[/eluser]
I think, you should avoid making cache of the page output in this case. You should use 'object cache' instead. Which will help you cache your php objects that might be causing the slow performance. And just don't cache the language files, and your problem will go away, hopefully. I don't see any sense to create a full rendered page cache when the app is dynamic. Only cache what is necessary.




Theme © iAndrew 2016 - Forum software by © MyBB