Storing Records during sessions to avoid db hits


I don’t know if this is the right place to ask such a question, pls suggest if not, i’ll post to the related forum.

I have an array() of models fetched from the db in single query, essentially inserted into an associative array based on some processing after fetching.

so you can assume that there are more that 50 model records in array().

So i have my array() completely populated before calling $this->render(‘view fille.php’, array(mydata);

Now i want to show these records one by one, one at a time, to the user.

How can i do that provided that I have already queried all records to show and next request from the user

should be satisfied from existed records populated at first place.

Please suggest how to do it…!


Big O

You need to study the ‘caching’ section of the Yii guide:


I use it like this:

	public static function getProjectNameFromIdentifier($identifier) {

    	$cacheKey = 'ProjectNameFromIdentifier_'.$identifier;

    	$name = '';

    	if(false === $name = Yii::app()->cache->get($cacheKey)) {

        	$project = Project::model()->find('identifier=?', array($identifier));

        	$name = $project->name;

        	$cacheDependency = new CDbCacheDependency("

       		SELECT `modified` FROM `bug_project`

              	WHERE `id` = {$project->id} LIMIT 1


        	Yii::app()->cache->set($cacheKey, $name, 0, $cacheDependency);


    	return $name;


I have this in my config:

    	'cache' => array(

        	'class' => 'system.caching.CFileCache',


Love that function jacmoe… nice…

Do I sense a slight touch of irony here? :lol:

no man… I truly do… there is no irony coming from a guy like me who proposed translations to definitive guide when they were already don… duh!

but, i believe that it could be a function to work a bit more on and be extended to a generic cache function instead of a specific one.

I will give it a thought and I will send it to you when i have bit of time…

Thanks Jacmoe…!

i’ll try this.

-Big O

This functionality is indeed required to speed up the things how ever there is one more question i wanted to ask here.

and that is.

since i have multiple records/models arranged in sequence (fetched by query based on some condition) of same type and i want to show the user each at a time.

how to do this…?

How to achieve a link list kind of functionality

i.e i provide a "Next" button to the user to fetch the next record in the sequence

for example my query fetched me 10 models in a sequence which are numbered based on some primary key

22, 45, 56, 88, 99, 101, 111, 125, 222, 225

so rather than rendering all the models i render each one by one, so lets pic to start with


I display model with 22 as primary key to the user and provide a "next" button on the view. user pressed "next" button and next model should be

with 45 as primary key along with a next button.

so my question is how to know what is the next record in the sequence

where should i store this information so that next record should be fetched from queried data collect at first time…?

is there any way to achieve that…?

Big O