Yii stores the cache content indexed by its "key" in the cache media. And it also stores the dependency specification (in your case the SQL to get the count) and the result of it (the count) with the content itself.
When it is accessed the next time, Yii checks the duration of the cache, and executes the dependency check. If everything is OK, then the cached content will be served.
I think you can select an appropriate "key" and/or "variation" for the page that you want to handle differently.