Skip to content

Instantly share code, notes, and snippets.

@phalcon
Last active December 10, 2015 05:58
Show Gist options
  • Save phalcon/4391207 to your computer and use it in GitHub Desktop.
Save phalcon/4391207 to your computer and use it in GitHub Desktop.
<?php
class MyManager extends Phalcon\Mvc\Model\Manager
{
protected $_cache;
public function setCache($cache)
{
$this->_cache = $cache;
}
public function executeQuery($phql, $variables=null, $bindParams=null)
{
$realPhql = preg_replace_callback('/:([a-z]+):/', function($matches) use ($variables) {
if (isset($variables[$matches[1]])){
return $variables[$matches[1]];
}
}, $phql);
$hash = sha1($realPhql);
if ($this->_cache->exists($hash)) {
$query = $this->createQuery($phql);
$resultset = $query->execute($variables);
$this->_cache->save($hash, $resultset);
return $resultset;
}
return $this->_cache->get($hash);
}
}
$a = new MyManager();
$a->executeQuery('SELECT * FROM Robots WHERE id > :id: AND type = :type:', array(
'id' => 100, 'type' => 'mechanical'
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment