“Web server”-level cache

We often use “plugins” like “WP Super Cache”… to have our contents using less server resources.
We also have to write various PHP-level code to having such functionality.

However, there is an alternative way to do it *automatically*, without having to repeatedly writing code to cache our content at PHP-level.

We care about 4 aspects of caching:
1-Where to cache (often files)
2-How long it cached (says 5 min or 30days, depend on how freshness the website)
3-Bypass for dynamic sections (login, admin, realtime…)
4-Clear cache

Assuming we using Nginx and passing request to backend PHP using socket, typically we having:

proxy_pass http://127.0.0.1:9000

We added something like:

proxy_cache_path defines place to put our cache data, naming “zone”. We have control over its size, how to creating sub- directories (levels=1:2 )

proxy_cache specifies which zone to store cache.

proxy_cache_key define the pattern to cache. We may need to add how to know that the page is dynamic generated, such as cookie. Or we may use proxy_cache_bypass to tell, example, wp-admin will be bypassed.

To clear cache, simply deletes files under zone directory!

Apache also having similar features, and if we need more flexible, a mature cache engine like Varnish may help us. Speed up and concentrate more on development!

この記事を書いた人
マイン

ベトナム生まれの開発者、私はPHPとかCSS/JS/HTML/Linux server経験があります。ひまの時に日本語は勉強します。

札幌市中央区北3条西26丁目3-8 N2ビル3F 〒064-0823 TEL:011-640-5437 FAX:011-640-5434
東京都港区六本木4丁目2-35 アーバンスタイル六本木三河台2F 〒106-0032 TEL:03-5772-1414 FAX:03-5772-1404
NADIA BANGKOK / 240 soi 52 Romklao Road Ladkrabang Bangkok 10520 Thailand
NADIA HANOI / 5F, SIMCO Bld., 28 Pham Hung, Ha Noi, Viet Nam
PAGETOP
ナディアFacebookページ株式会社ナディア|Nations Media Design Nadia
PAGE TOP ↑