If this is a small object that does not take up much memory and is serialized, you can simply save it in the session:
function getSessionObject($objectName, $params){
$sessionObjectSerialized = getSessionVariable($objectName, FALSE);
if($sessionObjectSerialized == FALSE){
$sessionObjectSerialized = constructSessionObject($objectName, $params);
setSessionVariable($objectName, $sessionObjectSerialized);
}
$sessionObject = unserialize($sessionObjectSerialized);
return $sessionObject;
}
function constructSessionObject($objectName, $params = array()){
switch($objectName){
case('gnugpg_key_ring'):{
$gnugpgKeyRing = getGNUPGKeyRing();
return serialize($countryScheme);
}
default:{
throw new UnsupportedOperationException("Unknown object name objectName, cannot retrieve from session.");
break;
}
}
}
function initSession(){
session_name('projectName');
session_start();
}
function setSessionVariable($name, $value){
$_SESSION['projectName'][$name] = $value;
}
function getSessionVariable($name, $default = FALSE){
if(isset($_SESSION['projectName'])){
if(isset($_SESSION['projectName'][$name])){
$value = $_SESSION['projectName'][$name];
}
}
return $default;
}
and then restore this object by calling
getSessionObject('gnugpg_key_ring');
, . , , , , , .
, , memcached, , .