Caching is one of the built in core features in orchid. Orchid supports three types of storage engine for orchid which are SQLite, MySQL and Memcache. You can take advantage of either one depending on your requirement. Lets have a look at how to work with caching engine in Orchid.

1. Setup configuration file

if you want SQLite as your caching storage, Use the following directives in your app/config/configs.php

$configs['cache_sqlite']['dbname']="sqlite.sq2"; 
//absolute path or it will be stored in app/cache
$configs['cache_source'] = "sqlite"; //or mysql or memcache

If you want MySQL as storage , use the following directives

$configs['cache_mysql']['dbname']="";
$configs['cache_mysql']['dbuser']="";
$configs['cache_mysql']['dbhost']="";
$configs['cache_mysql']['dbpass']="";
$configs['cache_mysql']['dbpersistence']=true;
 
$configs['cache_source'] = "mysql";

You need to create a table named `cache` with following schema

CREATE TABLE `cache` (
  `marker` varchar(250) NOT NULL,
  `content` text,
  `valid` int(11) DEFAULT NULL,
  `modified` int(11) DEFAULT NULL,
  PRIMARY KEY  (`marker`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

If you use Memcache as storage, use the following directives

$configs['cache_memcache']['servers'][]=array("host"=>"","port"=>"");
$configs['cache_memcache']['servers'][]=array("host"=>"","port"=>"");
...
as many you want
 
$configs['cache_source'] = "memcache";

2. Now take a look at the code of the controller

<?
class cachetest extends controller
{
	function base()
	{
		$this->use_view=false;
		$cache = loader::load("cache");
 
		$cache->set("key1","Hello World",2);
		$cache->set("key2","Hello World2",5);
		sleep(3);
 
		if ($cache->isExpired("key1"))
		echo "This key has been expired after 2 seconds";
 
		echo $cache->get("key1").":".$cache->get("key2");
 
 
	}
}
?>