} */ public static $sections = []; } /** * @author Christian Fraß */ class struct_subject_apc { /** * @var string * @author Christian Fraß */ public $section; /** * @var list * @author Christian Fraß */ public $ids; /** * @param string $section * @author Christian Fraß */ public function __construct( string $section ) { $this->section = $section; $this->ids = []; } } /** * @param struct_subject_apc $subject * @param string id * @return string * @author Christian Fraß */ function _apc_id( struct_subject_apc $subject, string $id ) : string { return ( ($subject->section === UNSET_STRING) ? $id : sprintf('%s_%s', $subject->section, $id) ); } /** * @param string $section * @return struct_subject_apc * @author Christian Fraß */ function apc_make( string $section = UNSET_STRING ) : struct_subject_apc { if ($section === UNSET_STRING) { $section = sprintf('alveolata_%d', count(_state_apc::$sections)); } if (in_array($section, _state_apc::$sections)) { throw (new \Exception(sprintf('APC section "%s" already in use', $section))); } else { array_push(_state_apc::$sections, $section); $subject = (new struct_subject_apc($section)); return $subject; } } /** * @param struct_subject_apc $subject * @param string $id * @param mixed $value * @author Christian Fraß */ function apc_set( struct_subject_apc $subject, string $id, $value ) : void { $id_ = _apc_id($subject, $id); array_push($subject->ids, $id_); \apc_store($id_, $value); } /** * @param struct_subject_apc $subject * @param string $id * @return bool * @author Christian Fraß */ function apc_has( struct_subject_apc $subject, string $id ) : bool { return \apc_exists(_apc_id($subject, $id)); } /** * @param struct_subject_apc $subject * @param string $id * @return mixed * @author Christian Fraß */ function apc_fetch( struct_subject_apc $subject, string $id ) { return \apc_fetch(_apc_id($subject, $id)); } /** * @param struct_subject_apc $subject * @author Christian Fraß */ function apc_clear( struct_subject_apc $subject ) : void { if ($subject->section === UNSET_STRING) { \apc_clear_cache(); } else { foreach ($subject->ids as $id_) { \apc_delete($id_); } $subject->ids = []; } } ?>