Skip to content

Instantly share code, notes, and snippets.

@tuxpower
Last active February 6, 2018 09:14
Show Gist options
  • Save tuxpower/1f7a1aac027934f9253aacbf64c660d4 to your computer and use it in GitHub Desktop.
Save tuxpower/1f7a1aac027934f9253aacbf64c660d4 to your computer and use it in GitHub Desktop.
Memcache in code using PHP
<?php
$memcache = new Memcache();
$memcache->addServer(‘172.16.0.1’, 11211);
$memcache->addServer(‘172.16.0.2’, 11211);

$myData = $memcache->get(‘myKey’);
if ($myData == false) {
   $myData = GetMyDataFromDB();
   // Put it in Memcache as ‘myKey’, without compression, with no expiration
   $memcache->set(‘myKey’, $myData, false, 0);
}

echo $myData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment