开发者

Storing cached data - what amount of formatting?

开发者 https://www.devze.com 2022-12-31 12:32 出处:网络
I am in the middle of a web app and we\'re just about to start with a cache-layer that features memcache and disk-based cache.

I am in the middle of a web app and we're just about to start with a cache-layer that features memcache and disk-based cache.

开发者_如何学JAVA

We just questioned ourself - what level/amount of formatting should we use on the stored cache data?

Let say that we have a database table called articles. Articles table have a number of columns including headline and content.

If we we're about to store this as an array, it would look like this:

 array ( 
         'headline' => 'Brilliant news - sunshine all week',
         'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
         semper mi. Aenean rutrum ultrices mauris sed dictum. ');

Or, the pre-formatted HTML version:

 <div class="article">
      <h1>Brilliant news - sunshine all week</h1>     
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
         semper mi. Aenean rutrum ultrices mauris sed dictum. </p>
 </div>

Pros and cons

Obviously, the pre-formatted html version increases the size of each cached datablock, since it includes a number of html tags. Also, there will be some headache included if the data were about to be formatted in different ways (I don't think that we will do this though). The option for that is of course to instead store multiple versions of each article in the cache.

So, what's common sense to do in our case? Let the HTML be rendered each time based upon the array that are retrieved from memcache, or just output the pre-formatted html?


I think it all depends on performance you need but I would use array version as it give possibility to play with content before rendering. Also building HTML having content is usually quite cheap when compared to getting content itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消