Caching

Yet another place where server-side programming can be used is to cache values, which are expensive to compute. The following is the basic pattern here:

  1. Check whether the value is cached.
  2. If it isn't, or the value is too old, compute and cache it.
  3. Return the cached value.

For example, calculating the sales for a company is the perfect item to cache. Perhaps, a large retail company has 1,000 stores with potentially millions of individual sales' transactions per day. If the corporate headquarters is looking for sales' trends, it is much more efficient if the daily sales numbers are precalculated at the store level instead of summing up millions of daily transactions.

If the value is simple, such as looking up a user's information from a single ...

Get PostgreSQL Server Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.