เว็บนี้มีลิงก์ affiliate บางลิงก์ — เราอาจได้รับค่าคอมมิชชันหากสมัครผ่านลิงก์เหล่านั้น · Some links are affiliate links. รายละเอียด
คู่มือ · Cache & Performance

Cache บน Hosting คืออะไร? วิธีตั้งค่าและเคลียร์ Cache 2026

Cache บน Hosting คืออะไร? วิธีตั้งค่าและเคลียร์ Cache 2026

Cache คือกลไกที่เก็บสำเนาของข้อมูลไว้ในที่ที่เข้าถึงได้เร็วกว่า ทำให้การโหลดครั้งต่อไปเร็วขึ้นมาก การเข้าใจและตั้งค่า cache อย่างถูกต้องเป็นหนึ่งในวิธีที่ง่ายที่สุดในการเร่งความเร็วเว็บไซต์

Cache is a mechanism that stores copies of data in faster-accessible locations, making subsequent loads much quicker. Properly configuring cache is one of the easiest ways to dramatically speed up your website.

ประเภทของ Cache

Browser Cache

บราวเซอร์เก็บสำเนา CSS, JavaScript, รูปภาพไว้ใน local เมื่อผู้ใช้กลับมาเยี่ยมชมไม่ต้องดาวน์โหลดซ้ำ ควบคุมผ่าน HTTP headers Cache-Control และ Expires

Server Cache / Page Cache

Server เก็บ HTML ที่ render แล้วไว้ ครั้งต่อไปที่มี request เหมือนกันจะส่ง cached HTML ทันทีแทนที่จะสร้างใหม่ ลด PHP processing และ database queries อย่างมาก

Object Cache

เก็บผลลัพธ์ของ database queries ไว้ใน memory (Redis, Memcached) เมื่อ query เดิมถูกเรียกซ้ำ ดึงจาก memory แทน database ทำให้เร็วขึ้นหลายร้อยเท่า

CDN Cache

Content Delivery Network เก็บสำเนาไฟล์ static ไว้ใน server หลายจุดทั่วโลก ผู้ใช้จะได้รับไฟล์จาก server ที่ใกล้ที่สุด ลด latency อย่างมีนัยสำคัญ

แนะนำAsiaGB.com — Web Hosting & VPS ที่เราแนะนำ เซิร์ฟเวอร์ในไทยและสิงคโปร์ สตอเรจ SSD จัดการผ่าน DirectAdmin พร้อมทีม Support ภาษาไทย 24 ชั่วโมง uptime 99%

AsiaGB.com — hosting & VPS we recommend: TH/SG servers, SSD storage, DirectAdmin, 24h Thai support, 99% uptime.

เยี่ยมชม AsiaGB →

ตั้งค่า Browser Cache ผ่าน .htaccess

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/html "access plus 0 seconds"
</IfModule>

ตั้ง cache สำหรับ static files 1 ปี แต่ HTML ไม่ cache (เพื่อให้ content อัพเดทเสมอ)

WordPress Cache Plugin

วิธีเคลียร์ Cache เมื่อจำเป็น

เมื่อไรที่ต้องเคลียร์ cache?

เคลียร์ Cache ใน WordPress

เคลียร์ Cloudflare Cache

Cloudflare Dashboard → Caching → Configuration → Purge Cache → Purge Everything หรือ Custom Purge เพื่อเคลียร์เฉพาะ URL

คำถามที่พบบ่อย (FAQ)

Cache ทำให้เว็บเร็วขึ้นเท่าไหร่?

ขึ้นอยู่กับ baseline แต่โดยทั่วไป page cache ลด TTFB (Time to First Byte) จาก 500ms+ เหลือ ไม่ถึง 100ms Browser cache ลด repeat visit load time ลงได้ 50-80%

Cache ทำให้ผู้ใช้เห็น content เก่าไหม?

ได้ ถ้า cache TTL ยาวและไม่เคลียร์ cache หลัง publish content ใหม่ ตั้ง cache TTL ให้เหมาะสม และ configure cache invalidation เมื่อมี update

ถ้าใช้ Cloudflare ต้องตั้ง cache อีกไหม?

Cloudflare cache ช่วยในระดับ CDN แต่ยังต้องตั้ง server cache ด้วย เพราะทั้งสองระดับทำงานต่างกัน Cloudflare = global CDN, server cache = ลด load ใน origin server

Cache ใช้พื้นที่ disk เยอะไหม?

ขึ้นอยู่กับจำนวนหน้าและขนาดไฟล์ page cache สำหรับเว็บทั่วไปใช้ 100MB-1GB ตรวจสอบพื้นที่ใน hosting และตั้งค่า cache expiry เพื่อล้าง cached files เก่าอัตโนมัติ