ADOdb Library for PHP Manual
Prev CacheExecute Next

CacheExecute([$secs2cache,]$sql,$inputarr=false)

Similar to Execute, except that the recordset is cached for $secs2cache seconds in the $ADODB_CACHE_DIR directory, and $inputarr only accepts 1-dimensional arrays. If CacheExecute() is called again with the same $sql, $inputarr, and also the same database, same userid, and the cached recordset has not expired, the cached recordset is returned.

    include('adodb.inc.php');
    include(
'tohtml.inc.php');
    
$ADODB_CACHE_DIR = '/usr/local/ADOdbcache';
    
$conn = &ADONewConnection('mysql');
    
$conn->PConnect('localhost','userid','password','database');
    
$rs = $conn->CacheExecute(15, 'select * from table'); # cache 15 secs
    
rs2html($rs); /* recordset to html table */  

Alternatively, since ADOdb 1.80, the $secs2cache parameter is optional:

    $conn->Connect(...);
    
$conn->cacheSecs = 3600*24; // cache 24 hours
    
$rs = $conn->CacheExecute('select * from table');

If $secs2cache is omitted, we use the value in $connection->cacheSecs (default is 3600 seconds, or 1 hour). Use CacheExecute() only with SELECT statements.

Performance note: I have done some benchmarks and found that they vary so greatly that it's better to talk about when caching is of benefit. When your database server is much slower than your Web server or the database is very overloaded then ADOdb's caching is good because it reduces the load on your database server. If your database server is lightly loaded or much faster than your Web server, then caching could actually reduce performance.


Prev Home Next
Execute Up ExecuteCursor

Sponsored by phpLens