Skip to content

Instantly share code, notes, and snippets.

@karptonite
Last active December 27, 2015 04:39
Show Gist options
  • Save karptonite/7268635 to your computer and use it in GitHub Desktop.
Save karptonite/7268635 to your computer and use it in GitHub Desktop.
A simplified version of our query caching system
<?php
//=================================================================================================
class GeekCache_SimpleQuery extends GeekCache_TrackedCache
{
//==============================================================================================
public function __construct( $query, $timelimit, $namespaces=array(), $filename = '' )
{
if ( !$filename )
$filename = 'query_' . md5( $query );
$this->_query = $query;
return parent::__construct( $filename, $timelimit, $namespaces );
}
//==============================================================================================
function GetRecords( $query, &$numitems=0, $debug=false, &$gotcache, $regen=false, $slave=false )
{
$dataobj = $this->get( $this->filename );
if ( $dataobj != null )
{
$dataobj = unserialize( $dataobj );
$records = &$dataobj->records;
$numitems = $dataobj->numitems;
}
else
{
$records = $GLOBALS[$database]->GetRecords( $query );
$countobj = $GLOBALS[$database]->GetRecord( "SELECT FOUND_ROWS() AS numitems" );
$numitems = $countobj['numitems'];
$newdataobj->records = &$records;
$newdataobj->numitems = $numitems;
$this->put( serialize( $newdataobj ) );
}
return $records;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment