Skip to content

Commit

Permalink
Cache the RI results for at least an hour.
Browse files Browse the repository at this point in the history
No need to check favouriteRecipients THAT frequently.
  • Loading branch information
mrubinsk committed Jan 27, 2014
1 parent c02329a commit 3a40cbd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion framework/Core/lib/Horde/Core/ActiveSync/Connector.php
Expand Up @@ -317,9 +317,25 @@ public function contacts_getActionTimestamp($uid, $action, $addressbook = null)
$uid, $action, $addressbook, $this->hasFeature('modseq', 'contacts'));
}

/**
* Returns the favouriteRecipients data for RI requests.
*
* @param integer $max The maximum number of recipients to return.
*
* @return array An array of email addresses.
*/
public function getRecipientCache($max = 100)
{
return $this->_registry->mail->favouriteRecipients($max);
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
$cache_key = 'HCASC:' . $this->_registry->getAuth() . ':' . $max;
if (!$cache->exists($cache_key, 3600)) {
$results = $this->_registry->mail->favouriteRecipients($max);
$cache->set($cache_key, json_encode($results));
} else {
$results = json_decode($cache->get($cache_key, 3600));
}

return $results;
}

/**
Expand Down

0 comments on commit 3a40cbd

Please sign in to comment.