Skip to content

Instantly share code, notes, and snippets.

@chukShirley
Created January 20, 2015 13:37
Show Gist options
  • Save chukShirley/35c693666955fe149b69 to your computer and use it in GitHub Desktop.
Save chukShirley/35c693666955fe149b69 to your computer and use it in GitHub Desktop.
Zend Data Cache
class ItemsGateway extends AbstractGateway
{
protected $table = 'SCF906';
public function fetchAll()
{
// Try to fetch from the cache first
$response = zend_shm_cache_fetch('itemCodes');
// If itemCodes list isn't in cache
if ($response === false){
$sql = "SELECT * FROM ".$this->table;
$stmt = $this->db->query($sql,[]);
$response = [];
while ($row = db2_fetch_assoc($stmt))
{
$response[] = array_map('trim',$row);
}
// Store the results in cache
zend_shm_cache_store('itemCodes',$response,24*3600);
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment