Skip to content

Commit

Permalink
Merge pull request #30 from LukasReschke/use-simple-array-cache
Browse files Browse the repository at this point in the history
Cache results of `getTimezoneNameNoLocationSpecific`
  • Loading branch information
mlocati committed Jan 17, 2015
2 parents 746398b + 5b69f44 commit 5b82f00
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions code/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
class Calendar
{
/** @var array */
protected static $timezoneCache;

/**
* Convert a date/time representation to a {@link http://php.net/manual/class.datetime.php \DateTime} instance.
* @param number|\DateTime|string $value An Unix timestamp, a `\DateTime` instance \DateTime or a string accepted by {@link http://php.net/manual/function.strtotime.php strtotime}.
Expand Down Expand Up @@ -402,6 +405,11 @@ public static function getDayperiodName($value, $width = 'wide', $locale = '', $
*/
public static function getTimezoneNameNoLocationSpecific($value, $width = 'long', $kind = '', $locale = '')
{
$cacheKey = json_encode(array($value, $width, $kind, $locale));
if(isset(self::$timezoneCache[$cacheKey])) {
return self::$timezoneCache[$cacheKey];
}

$result = '';
if (!empty($value)) {
$receivedPhpName = '';
Expand Down Expand Up @@ -502,6 +510,8 @@ public static function getTimezoneNameNoLocationSpecific($value, $width = 'long'
}
}

self::$timezoneCache[$cacheKey] = $result;

return $result;
}

Expand Down

0 comments on commit 5b82f00

Please sign in to comment.