diff --git a/libraries.module b/libraries.module index 059bfea..f23eb11 100644 --- a/libraries.module +++ b/libraries.module @@ -412,16 +412,6 @@ function libraries_info_defaults(&$library, $name) { /** * Tries to detect a library and its installed version. * - * @todo We need to figure out whether, and if, how we want to retain the - * processed information. I.e. either use a static cache here, or make - * libraries_info() conditionally invoke libraries_detect($name). D7 only way: - * Re-use drupal_static() of libraries_info() - but would still require to - * update the (DB) cache (there likely will be one soon). Also, we probably do - * not want to ALWAYS parse ALL possible libraries; rather, the - * requesting/consuming module likely wants to know whether a list of - * supported libraries (possibly those registered by itself, or in a certain - * "category") is available... Food for thought. - * * @param $name * The machine name of a library to return registered information for. * @@ -441,6 +431,12 @@ function libraries_info_defaults(&$library, $name) { * @see libraries_info() */ function libraries_detect($name) { + $libraries = &drupal_static(__FUNCTION__, array()); + + if (isset($libraries[$name])) { + return $libraries[$name]; + } + $library = libraries_info($name); $library['installed'] = FALSE; @@ -454,7 +450,8 @@ function libraries_detect($name) { $library['error message'] = t('The %library library could not be found.', array( '%library' => $library['name'], )); - return $library; + $libraries[$name] = $library; + return $libraries[$name]; } // Invoke callbacks in the 'pre-detect' group. @@ -476,7 +473,8 @@ function libraries_detect($name) { $library['error message'] = t('The version of the %library library could not be detected.', array( '%library' => $library['name'], )); - return $library; + $libraries[$name] = $library; + return $libraries[$name]; } } @@ -495,7 +493,8 @@ function libraries_detect($name) { '%version' => $library['version'], '%library' => $library['name'], )); - return $library; + $libraries[$name] = $library; + return $libraries[$name]; } // Apply version specific definitions and overrides. @@ -538,7 +537,9 @@ function libraries_detect($name) { // Invoke callbacks in the 'post-detect' group. libraries_invoke('post-detect', $library); - return $library; + $libraries[$name] = $library; + + return $libraries[$name]; } /**