Welcome Guest, Not a member yet? Register   Sign In
Benchmark class and _output function together with cache enabled (SOLVED)
#11

[eluser]CroNiX[/eluser]
[quote author="luismartin" date="1337722154"]

Edit: I've just recalled the pseudovariable {elapsed_time}
http://ellislab.com/codeigniter/user-gui...utput.html

Would this work in my case?[/quote]Probably not with cached files. You lose a lot of control once you start to use CI's simplistic built-in caching mechanism. Again, if a cached file exists, CI will serve that instead of actually processing the request (which is where the elapsed_time gets parsed). The {elapsed_time} would have already be rendered in the cached file.
#12

[eluser]Aken[/eluser]
It can be done easily. The trick is to pass the cached content to the output class, which will then parse the {elapsed_time} or similar variables and output from there.

Here's a dumbed down example using a Cache driver that comes with CodeIgniter:

Code:
public function index()
    {
     $this->load->driver('cache', array('adapter' => 'file'));
    
     if ( ! $display = $this->cache->get('home'))
     {
      $display = $this->load->view('home', null, true);
        
         $this->cache->save('home', $display, 60*45); // Save to cache for 45 minutes.
     }
    
     $this->output->set_output($display);
    }
#13

[eluser]luismartin[/eluser]
ok. Jeez! hehe! Never guessed something so apparently simple would be so hard to work around in CI. Kind of a drawback, despite I still love CI.

Then my only option at the moment would be to extend Output, and append or prepend the comment to </html>. What do I finally do guys? Before, or after </html>? It the latter might actually mess some browser I will finally use preg_match()

Edit: I didn't see your Aken's last post when writing this one.
#14

[eluser]Aken[/eluser]
I just tested it, and {elapsed_time} works with both the Output class cache, and with the cache driver example that I posted. So if you're having trouble using it, post your code. You shouldn't need to extend the Output class, nor should you need the _output() controller method.
#15

[eluser]luismartin[/eluser]
Aken, so following your solution, I wouldn't need the benchmark class, would I? Just {elapsed_time} placed wherever I want it to appear?
#16

[eluser]Aken[/eluser]
You wouldn't need the benchmark class for either of those solutions. Technically the class is instantiated automatically already, anyway.

If you are using the Output class caching already, all you need to do is add {elapsed_time} to your view.
#17

[eluser]luismartin[/eluser]
Perfect! I think that's all for now. I'll get down to it tomorrow and let you know.

Thanks a lot both both of you!
#18

[eluser]luismartin[/eluser]
Hello again mates!

I tried {elapsed_time} even without needing to prefetch the cached content in order to parse the pseudovariable before saving and delivering. To my surprise it works just putting it in my main view (just before </html&gtWink. I didn't use any Output method to get it. You might think that once the file is cached, the parsed value is always the same string hardcoded in the cached file. Nope, it varies a bit.

I've just checked the loading times of a regular page, and prior to being cached it lasted 0.1506. Once cached it lasts 0.0056, 0.0062 or so, not always the same time, which shows that it's still being parsed despite it's cached.

Regards!
#19

[eluser]luismartin[/eluser]
One more thing to mention.

I've just checked, although now I see it's such an obvious thing, that CI stores in cache the {elapsed_time} pseudovariable without parsing it. The parsing is always made once you have the final output, whether it comes from cache or it has been just rendered.
#20

[eluser]Aken[/eluser]
Correct. The output class will always do a small amount of processing on the final output, whether it comes from a cache file or not. You can circumvent this if you want to be more strict with your cache, but for a lot of situations it works great.




Theme © iAndrew 2016 - Forum software by © MyBB