Kotchasan Framework Documentation
Cache System Overview
Cache System Overview
ระบบ Cache ของ Kotchasan ช่วยเพิ่มประสิทธิภาพแอปพลิเคชันโดยเก็บข้อมูลไว้ใช้ซ้ำ
สารบัญ
ภาพรวม
| Class | คำอธิบาย | เหมาะสำหรับ |
|---|---|---|
| MemoryCache | เก็บในหน่วยความจำ | Request scope |
| FileCache | เก็บในไฟล์ | Single server, persistent |
| RedisCache | เก็บใน Redis | Multiple servers, high performance |
| QueryCache | Cache สำหรับ DB queries | Database optimization |
การใช้งานพื้นฐาน
use Kotchasan\Cache\CacheFactory;
// สร้าง cache ตาม config
$cache = CacheFactory::create([
'driver' => 'file',
'path' => ROOT_PATH . 'datas/cache/'
]);
// CRUD operations
$cache->set('key', $value, 3600); // เก็บ 1 ชั่วโมง
$value = $cache->get('key'); // ดึงค่า
$cache->delete('key'); // ลบ
$cache->has('key'); // ตรวจสอบ
$cache->clear(); // ล้างทั้งหมดการเลือก Cache
// Development: ใช้ MemoryCache
$cache = new MemoryCache();
// Single Server Production: ใช้ FileCache
$cache = new FileCache(['path' => '/tmp/cache/']);
// Multiple Servers: ใช้ RedisCache
$cache = new RedisCache('redis.example.com', 6379);Cache Classes
- MemoryCache - Cache ในหน่วยความจำ
- [FileCache] - Cache ในไฟล์
- RedisCache - Redis Cache
- QueryCache - Cache สำหรับ Query
- CacheFactory - Factory สำหรับสร้าง Cache