cache invalidation

before i go deeper into documentation and code i would like for someone to answer couple of simple questions:

  1. how does caching happen? is it doing it by itself? is it time based or invalidates when necessary?

  2. (assuming i am using AR) when i fetch a row by id is it cached by itself or do i have to cache stuff myself? if i fetch a set, is it all cached? when i later modify that row, or set, how is it invalidated? if i perform a manual sql statement, it is going to invalidated affected keys in cache?

i hope i am clear on the questions.

  1. Caching is done how it is done all the time. You want an item (or page fragment, or a whole page or whatever). First you check whether a cached one exists. Then cache validates both if it’s expired and if all the dependencies validate the value.

If there isn’t cache hit (time expired, file is changed, row has been updated, or there hadn’t been any cached item at all etc.), then the script generate the item and save.

  1. ActiveRecords are not cached. They are only stored in variables. (However, you can cache them manually of course.)

yeah, that was the main question here, do i cache stuff myself, or Yii has a magic mechanism of doing it itself as long as i manipulate DB using DAO.