Two Caches Needed?

Hey,

I’ve read the yii guide regarding the caching features and I have a question. Let’s say I

have the following code:

– Controller –

$data = MyModel::model()->getData();

$this->render(‘view’, array(‘data’=>$data));

– View –

<table>

<?php foreach($data as $k=>$v): ?>

//echo out

<?php endforeach; ?>

</table>

I want to cache the result, so at first I would try to cache the table fragment with beginCache

and endCache. After that the table is cached, but the data gets retrieved and calculated from the

model every request. So I would use a data cache to cache the variable $data in my controller.

Afterwards I have two caches, but there is the problem: I have a greater efford to detect an

error if the cache is not up to date. And I must control that the caching time of the fragment cache

is the same as the data cache.

Is there a possibility to do this scenario easier and better?

Thanks!

Could you please try to follow that article

I hope you will get a good result after implementing it. ;)

Thank you for your response. But it is not about what caching method to use (sqlite, file, apc, memcache), but how to code the given scenario.

Double caching is hardly ever worth it. You might run into all sorts of synchronization issues. In your specific case, you should only considder it if both, fetching the result set from the db and rendering the presentation of your data turns out to be expensive. From the looks of it, I’d say stick to query/data caching.