Created
May 14, 2015 10:50
-
-
Save gherkins/2491b7db2cd2d206d29b to your computer and use it in GitHub Desktop.
cache identical queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class CachedMySQLDatabase | |
* @inheritdoc | |
*/ | |
class CachedMySQLDatabase extends MySQLDatabase | |
{ | |
protected $cache = array(); | |
public function query($sql, $errorLevel = E_USER_ERROR) | |
{ | |
$cacheKey = crc32($sql); | |
if (isset($this->cache[$cacheKey])) { | |
return $this->cache[$cacheKey]; | |
} | |
$res = parent::query($sql, $errorLevel = E_USER_ERROR); | |
$this->cache[$cacheKey] = $res; | |
return $res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment