Hi there.

My site has a dropdown list populated with a list of approx 280 rows from a database.

To increase eprformance on page load times I would like to cache this list so that it is not calling from the database everytime.

Can anyone suggest a method for doing this?

Many thanks!

Will

    There are a few ways you can do this.

    The industrial-strength method would be to use something like memcached but it sounds like this may be overkill for what you need.

    A simpler method would be to make your query and then serialize the array to either the filesystem or to a database table made to store cached data.

    Then you only have to unserialize the data to have the array back in its original state.

    On your management side, when the contents of the dropdown change, you can re-create the serialized array.

    Wes

      Or, assuming this dropdown list is pretty static (otherwise caching wouldn't be very effective)...

      Assuming the cached version doesn't already exist (first thing to do is check), generate the HTML of the dropdown list and save it in a file. That's your cached version. Don't forget to actually output it as well, of course. If the cached version does exist, just output that.

        Write a Reply...