You are here

function _wunderground_weather_cache in Wunderground weather 7

Retrieve data from cache or make a new http request.

Parameters

string $type: Current weather conditions or weather forecasts.

Return value

array An array containing all weather data for a block.

2 calls to _wunderground_weather_cache()
wunderground_weather_get_current in ./wunderground_weather.module
Get current weather conditions and return them.
wunderground_weather_get_forecast in ./wunderground_weather.module
Get forecast data and return a themed table.

File

./wunderground_weather.module, line 714
Wunderground weather module to display weather forecasts and current weather conditions in blocks.

Code

function _wunderground_weather_cache($type, $block_number) {
  global $language;
  $langcode = $language->language;

  // Check if we need to use cache.
  if (variable_get('wunderground_weather_cache', 1)) {

    // Get data from cache.
    $cache = cache_get('wunderground_weather_' . $type . '_' . $block_number . '_' . $langcode);
    if ($cache && $cache->expire > time()) {
      $weather = $cache->data;
    }
    else {

      // Get new data from Wunderground and store in the cache.
      $weather = call_user_func('wunderground_weather_get_' . $type . '_data', $block_number);
      $expire = time() + variable_get('wunderground_weather_cache_expire', 86400);
      cache_set('wunderground_weather_' . $type . '_' . $block_number . '_' . $langcode, $weather, 'cache', $expire);
    }
  }
  else {
    $weather = call_user_func('wunderground_weather_get_' . $type . '_data', $block_number);
  }
  $weather['block_number'] = $block_number;
  return $weather;
}