Thursday, 28 July 2011

CGlobalStateCacheDependency COutputCache invalidation performance?

Hi,

I'm using COutputCache to cache the new index, news pages and feed pages on my new site and had a requirement to invalidate these at will, I worked out that I could use CGlobalStateCacheDependency with a unique key and then simply change that particular state when I wished to invalidate the output cache. My only concern however is performance, I understand that the GlobalState is stored in the runtime/state.bin file, does this mean that every time someone hits one of my cached pages Yii is reading that file or does it cache the state in Cache() ?

Here's some code snippets:

From FeedsController:

public function filters()
{
        $newsDependency
= New CGlobalStateCacheDependency('cacheNews');
       
return array(
                array
(                                          // Cache RSS feeds
                       
'COutputCache',
                       
'duration'=>900,    // 15 minutes
                       
'dependency'=>$newsDependency,
               
),
       
);
}



From my model whenever I need to invalidate anything which has the 'cacheNews' dependency:

Yii::app()->setGlobalState('cacheNews', microtime(true));



This works really well but again I'm concerned about performance and scalability.

No comments:

Post a Comment