Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 1.25 KB

README.md

File metadata and controls

66 lines (49 loc) · 1.25 KB

Phalcon\Cache\Backend

Usage examples of the adapters available here:

Database

This adapter uses a database backend to store the cached content:

$di->set('cache', function() {

	// Create a connection
	$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
	    "host" => "localhost",
	    "username" => "root",
	    "password" => "secret",
	    "dbname" => "cache_db"
	));

	//Create a Data frontend and set a default lifetime to 1 hour
	$frontend = new Phalcon\Cache\Frontend\Data(array(
	    'lifetime' => 3600
	));

	//Create the cache passing the connection
	$cache = new Phalcon\Cache\Backend\Database($frontend, array(
		'db' => $connection,
		'table' => 'cache_data'
	));

	return $cache;
});

This adapter uses the following table to store the data:

 CREATE TABLE `cache_data` (
  `key_name` varchar(40) NOT NULL,
  `data` text,
  `lifetime` int(15) unsigned NOT NULL,
  PRIMARY KEY (`key_name`),
  KEY `lifetime` (`lifetime`)
)

Using the cache adapter:

$time = $this->cache->get('le-time');
if ($time === null) {
    $time = date('r');
    $this->cache->save('le-time', $time);
}

echo $time;

Wincache

This adapter uses windows cache extension for PHP