DropDownList connected to database table with caching?


I am relative new with Yii. By trying to find the solution by myself I found more questions than answers. So I hope someone from you guys could help we with my issue.

Some forms in my webapp holds a dropDownList to choose from. The values of these lists are similar to the t_lookup example in the blog tutorial. I have tables that holding fix Masterdata, like t_person_types, t_supported_devices or t_gender as t_person_titles. The structure of these tables are like a key, value pair.

t_person_types : person_type_id bigint, person_type varchar(x)


t_gender: gender_id bigint, gender varchar(x)

These tables holding mainly static text, that may be an object to change, but would be mainly fix. In this example it could be possible that someone would add a new person_type as the gender would be fix over all time.

Now I am searching for a consistent and efficient way to retrieve the data for the dropDownList and for the text representation on the normal view. The solution should be using a cache otherwise the database would be spoiled by to many requests.

Is there a way to handle this in a own function that I could use in all Controllers without writing this infrastructure code over and over? And how could I improve the performance by using the cache? It here a way to simply turn on the cache and leave everything else to the framework, buzz word "cross concern"? I do not like the idea to handle the caching on every model again and again. And If i missed the part in the beginning I had to rewrite all models/controllers.

The only source I found in this matter was the documentation of Yii http://www.yiiframework.com/doc/guide/1.1/en/caching.data.

Thanks in advanced,


Can someone start giving me a hint or a starting point. Even if you do not know the complete answer maybe we could evolve a solution all together.



I think the first thing is to question whether or not to make the field options a database table, or the output of an array within a model method.

For example, I frequently have stuff like this in the model:

public function getGenderOptions($gender=null)







  //return specific gender requested by key

  return $genders[gender];


  //if not specified return array of choices, to be used in dropdowns, etc.

  return $genders;