On my new site i am displaying most of the images instead of text. I show images for recently written, recently viewed, mostly viewed posts etc. I found that in 40% of cases posts are same. so i need not to hit the DB to extract the image. It can save number of hits to Db & processing time.

I intially thought to cache post IDs. So before querying to DB or processing contents to extract image, i can search for post id into cache. If post id found in cache then i can directly show image from disk.

I found that there are many of the plugins who cache DB queries and their result. I am using wp-total cache. Please tell me whether it can fulfill my requirement or i should write my own logic

  • did you make sure that Database Cache is enabled? – Bainternet May 25 '11 at 15:44
  • @Bainternet my plugin can be used any person. and i can check for only me. I m asking whether wp total cache can fulfill my need – Amit Kumar Gupta May 26 '11 at 2:06
  • Well if that is the question then yes its good for your needs. – Bainternet May 26 '11 at 5:42
  • Do you mean you use code like get_post_thumbnail() to get the featured images of the posts? Many of these API functions use an internal cache, so if you call them multiple times on the same page they only query the database once. Can you edit your question to include some example code? – Jan Fabry May 27 '11 at 14:26
  • NO. I had written my own function to extract the image from post. My question is whether i should write code for caching or plugins like w3 total cache, super cache etc can do it automatically – Amit Kumar Gupta May 27 '11 at 18:25

As long as you use WP API ($wpdb) to perform queries, they will be cached by caching plugins (well, by those that have such functionality).

If you need to cache data that is more compelx to generate rather than just retrieve look into Transients API.

  • I think i must write my own mechanism for caching. if there is some plugin who does it automatically it'll not degrade performance at all. Thanks to suggest me Transients API – Amit Kumar Gupta Jun 2 '11 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.