Kotchasan Framework Documentation
Cache System Overview
Cache System Overview
Kotchasan's Cache system improves application performance by storing data for reuse.
Table of Contents
Overview
| Class | Description | Best For |
|---|---|---|
| MemoryCache | In-memory storage | Request scope |
| FileCache | File-based storage | Single server, persistent |
| RedisCache | Redis storage | Multiple servers, high performance |
| QueryCache | DB query caching | Database optimization |
Basic Usage
use Kotchasan\Cache\CacheFactory;
// Create cache based on config
$cache = CacheFactory::create([
'driver' => 'file',
'path' => ROOT_PATH . 'datas/cache/'
]);
// CRUD operations
$cache->set('key', $value, 3600); // Store for 1 hour
$value = $cache->get('key'); // Retrieve
$cache->delete('key'); // Delete
$cache->has('key'); // Check existence
$cache->clear(); // Clear allChoosing a 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 - In-memory cache
- [FileCache] - File-based cache
- RedisCache - Redis Cache
- QueryCache - Query Cache
- CacheFactory - Cache Factory