You are here

protected static function Module::memoize in Plug 7

Memoize function to cache method results.

Parameters

string $method_name: The method to execute name.

Return value

array The function result

2 calls to Module::memoize()
Module::getDirectories in src/Util/Module.php
Generates the cached array of enabled module directories.
Module::getNamespaces in src/Util/Module.php
Generates the cached array of available namespaces for plugins.

File

src/Util/Module.php, line 55
Contains Drupal\plug\Util\Module.

Class

Module

Namespace

Drupal\plug\Util

Code

protected static function memoize($method_name) {
  $cache_name = 'module_' . drupal_strtolower($method_name);
  $data =& drupal_static($cache_name);
  if (isset($data)) {
    return $data;
  }
  if ($cache = cache_get($cache_name)) {
    $data = $cache->data;
    return $data;
  }
  $data = call_user_func_array(array(
    get_called_class(),
    $method_name,
  ), array());
  cache_set($cache_name, $data);
  return $data;
}