Does renderPartial caches content of view files?

I need to render and display instances of different models(comments, polls, etc) on the same page. Those instances are sorted by date, so it is possible that there will be couple comments then poll then another commetns and once more poll and so on.

So I am calling renderPartial in a loop. I am afraid that this can work slow as each renderPartial needs to read file from hdd.

So my question is: does renderPartial caches content of the file somewhere in the memory during one http request? So calling renderpartial multiple times will not touch hdd every time.

  1. CController::renderPartial as a PHP function is loaded from HDD just once and resides in the memory during the life cycle of the request.

… You have to access HDD not only once but several times. Because the function relies on many other classes and functions, we have to load them altogether.

[s]2) a partial view file also gets loaded from HDD first time it is accessed and stays in the memory.

… If you use 3 different partial view files (post, comment and poll), then HDD is accessed 3 times.[/s]

  1. a partial view file gets loaded from HDD every time it is accessed.

… If you use 3 different partial view files (post, comment and poll), and you have 4 posts, 4 comments and 5 polls, then HDD is accessed 13 times.

… I’m not very sure if PHP behaves more clever in order to minimize the access count.

  1. the contents of the particular partial view is loaded from HDD (probably from database) every time it is displayed.

… If you have 4 posts, 4 comments and 5 polls, then you will access HDD or DB 13 times.

It’s a common practice to use some kind of cache (APC for example) to improve the performance regarding 1) and 2). It caches PHP files in memory and reduces the time needed to load them.

http://www.yiiframework.com/doc/guide/1.1/en/topics.performance

It’s very easy to use and very much effective. :)

For 3), we would use data caching to improve the performance.

http://www.yiiframework.com/doc/guide/1.1/en/caching.overview

It’s a little complicated. :(

Shouldn’t the file system already care for caching when you access the same file multiple times? Maybe you should test the performance impact. See http://www.yiiframework.com/doc/guide/1.1/en/topics.logging#performance-profiling and check if performance degrades as much as you fear.