1. Go to this page and download the library: Download kodhe/driver library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kodhe / driver example snippets
// application/libraries/Cache.php
class Cache extends \Kodhe\Driver\DriverLibrary
{
protected $valid_drivers = ['file', 'apcu', 'redis', 'memcached'];
public function __construct()
{
parent::__construct();
}
}
// application/libraries/Cache/drivers/Cache_file.php
class Cache_file extends \Kodhe\Driver\AbstractDriver
{
public function isSupported(): bool
{
return is_writable(APPPATH . 'cache/');
}
public function get($key)
{
// Implementation
}
public function save($key, $data, $ttl = 60)
{
// Implementation
}
}
class UserController extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('cache');
}
public function index()
{
// Akses driver via magic getter (lazy loaded)
$data = $this->cache->file->get('user_data');
// Atau explicit load
$this->cache->load_driver('file');
$data = $this->cache->file->get('user_data');
// Cek apakah driver supported
if ($this->cache->file->isSupported()) {
$this->cache->file->save('key', 'value', 300);
}
}
}