* @author Christian Fraß */ function get_with_info( interface_cache $cache, string $id, \Closure $retrieve ) { if (! $cache->has($id)) { $value = $retrieve(); $cache->set($id, $value); return ['fetched' => false, 'value' => $value]; } else { $value = $cache->fetch($id); return ['fetched' => true, 'value' => $value]; } } /** * @param string $id * @param Closure $retrieve * @return mixed * @author Christian Fraß */ function get( interface_cache $cache, string $id, \Closure $retrieve ) { return get_with_info($cache, $id, $retrieve)['value']; } /** * @param string $id * @param Closure $retrieve * @return mixed * @author Christian Fraß */ function clear( interface_cache $cache ) { return $cache->clear(); } /** * @author Christian Fraß */ function make( string $kind, array $parameters = [] ) : interface_cache { switch ($kind) { default: { throw (new \Exception(sprintf('invalid cache kind "%s"', $kind))); break; } case 'none': { return ( implementation_none::make( ) ); break; } case 'memory': { return ( implementation_memory::make( ) ); break; } case 'apc': { return ( implementation_apc::make( $parameters['section'] ?? UNSET_STRING ) ); break; } } }