- PostgreSQL Server Programming(Second Edition)
- Usama Dar Hannu Krosing Jim Mlodgenski Kirk Roybal
- 276字
- 2021-07-23 20:36:47
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:
- Check whether the value is cached.
- If it isn't, or the value is too old, compute and cache it.
- 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 table based on the user ID, you don't need to do anything. The value gets cached in PostgreSQL's internal page cache, and all lookups to it are so fast that even on a very fast network, most of the time is spent doing the lookups in the network and not in the actual lookup. In such a case, getting data from a PostgreSQL database is as fast as getting it from any other in-memory cache (such as memcached) but without any extra overhead in managing the cache.
Another use case of caching is to implement materialized views. These are views that are precomputed only when required, not every time one selects data from the view. Some SQL databases have materialized views as separate database objects, but in the PostgreSQL versions prior to 9.3, you have to do it yourself using other database features to automate the whole process.
- Learning Single:page Web Application Development
- Python for Secret Agents:Volume II
- 精通搜索分析
- Designing Hyper-V Solutions
- The DevOps 2.4 Toolkit
- C語言實驗指導(dǎo)及習(xí)題解析
- Unity 5.x By Example
- AutoCAD VBA參數(shù)化繪圖程序開發(fā)與實戰(zhàn)編碼
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Java EE 8 Application Development
- Test-Driven Machine Learning
- 細(xì)說Python編程:從入門到科學(xué)計算
- C編程技巧:117個問題解決方案示例
- INSTANT LESS CSS Preprocessor How-to
- 計算機程序的構(gòu)造和解釋(JavaScript版)