Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What methods of caching, other than to file or database, are available?

Currently I know of only two ways to cache data (I use PHP but I assume that the same will apply to most languages).

  1. Save the cache to a file
  2. Save the cache to a large DB field

Are there any other (perhaps better) ways of caching or is it really just this simple?

like image 656
Teifion Avatar asked Aug 06 '08 22:08

Teifion


1 Answers

Maybe you want to explicit more precisely what you want to cache. You have all this opportunities to cache:

  • Accessing the Data Base where you cache the data first correctly tuning your RDBMS, then using a layer to delegate the decision to detect multiple queries for the same data (with AdoDB for example.)
  • Extracting calculations from loops in the code so you don't compute the same value multiple times. Here your third way: storing results in the session for the user.
  • Precompiling the PHP code with an extension like APC Cache. This way you don't have to compile the same PHP code for every request.
  • The page sent to the user making sure you're setting the right META tags (do a good thing for the world and don't use ETL at least absolutly necessary); or maybe making dynamic pages completely static (having a batch process that generates .html pages); or by using a proxy cache like Squid.
  • Prefetching and by this I refer all those opportunities you have to improve the user experience just by doing things while the user don't look your way. For example, preloading IMG tags in the HTML file, tunning the RDBMS for prefectching, precomputing results storing complex computations in the database, etc.

From my experience, I'd bet you that your code can be improved a lot before we start to talk about caching things. Consider, for example, how well structured is the navigation of your site and how well you control the user experience. Then check your code with a tool like XDebug.

Verify also how well are you making your SQL queries and how well are you indexing your tables. Then check your code again to look for opportunities to apply the rule "read many times but write just once"

Use a simple tool like YSlow to hint other simple things to improve. Check your code again looking for opportunities to put logic in the browser (via JavaScript)

like image 146
ggasp Avatar answered Nov 16 '22 01:11

ggasp