get id of saved record in cache table


i have a query like this


i have 2 questions.

1)how to get id of saved record in yiicache table?

2)how do i know if cache expired in query and result is not from cache ?

As far as I know there is no elegant way to do that with CActiveRecord but the question is: Why do you need that? If you want to be sure your book is always in cache you could set the first parameter to an insane number. If you need to invalidate the cache (like when a book was updated etc.) you can use this extension as a cache dependency:

If - for some reason - you really need to know if the row is in the cache or not you will have to know the cache key. Yii generates a pretty long one to avoid collisions but nobody prevents you from using your own like


if you want to check if a model is in cache use






    return $book;


else //IN CACHE

    return $cachedBook;

thank u for solution. i test it. but in your way i have to save values by my own.

i think there should be a way to get generated id by yii.

any idea?

There is no way that I know of. Look at CDbCommands queryInternal method to see how the cache key is defined:


If you enable tracing in your log routes you should see the autogenerated cache key