function updateCachedRecord($id) { global $memcache; $key = DATABASE . ":record:" . $id; try { $record = @$memcache->get($key); if ($record) { // will only update if previously cached $record = loadBareRecordFromDB($id); $memcache->set($key, $record); } } catch (Exception $e) { } }
function updateCachedRecord($id) { global $memcache; if (!$memcache) { $memcache = new Memcache(); if (!$memcache->connect('localhost', MEMCACHED_PORT)) { return array("error" => "couldn't connect to memcached"); } } $key = DATABASE . ":record:" . $id; $record = $memcache->get($key); if ($record) { // will only update if previously cached $record = loadBareRecordFromDB($id); $memcache->set($key, $record); } }