views:

52

answers:

1

I de-normalized my database, since the application was crawling otherwise, and Im storing a list of categories for each item in the DB as a raw html version, and simply echoing it out in my design. Each category is actually a link, which is include a tag. Naturally, this is abit of a pain, especially if I want to change the look of how the category links are displayed, since I gotta update all the old cached entries.

What if I were to store this data as a serialized array instead, and simply unserialize it, and then apply formatting to it in php. Would there be a significant performance decrease over simply echoing out the raw html?

A: 

It's a bad idea to store values serialized only for a specific language in a database.

Did you consider memcache to reduce "crawls" of your database? I usually find caching to be a much more elegant and flexible solution than a de-normaliezd database.

Matthew
Already use memcache, except there are 2 million objects, which need to be recached several times a day, so the BUILDING of the cache should be optimized.
Yegor
Two million objects each have their own HTML list of categories? I suppose you'll need to share more details about your application if you want an answer more detailed than "no, don't store serialized PHP objects in a database."
Matthew
Its a movie listing application. I need to show movie genres + actors associated with each movie, which all have to be clickable links. I store the movie-actor, movie-genre, movie-director ID pairs in relational tables, but when there are 1.5 million movies, and each movie has an average of 15 actors, that creates a very large lookup table, that it would need to query on every cache build. thats why I store the actual lists as raw html in a special column of every item in the DB.
Yegor
Andrew Heath
Those sound like very fast queries if properly indexed. You shouldn't need to cache HTML in the database.
Matthew
If your site grows to the point where your database becomes a bottleneck, lazily cache the entire page in memcache. Presumably only a small subset of movies receive multiple hits per hour, and those are the only pages that would benefit from caching.
Matthew