Skip to content

Commit

Permalink
Cache avatar data
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Dec 3, 2014
1 parent 9be0ae6 commit 20c98f3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion imp/lib/Contacts/Image.php
Expand Up @@ -26,6 +26,13 @@ class IMP_Contacts_Image
const AVATAR = 1;
const FLAG = 2;

/**
* Cache timeout (in seconds).
*
* @var integer
*/
public $cache_timeout = 3600;

/**
* The e-mail address.
*
Expand Down Expand Up @@ -56,7 +63,7 @@ public function __construct($email)
*/
public function getImage($type)
{
global $conf;
global $conf, $injector;

if (!empty($conf['contactsimage']['backends'])) {
switch ($type) {
Expand All @@ -71,11 +78,31 @@ public function getImage($type)
break;
}

$cache = $injector->getInstance('Horde_Cache');
$pack = $injector->getInstance('Horde_Pack');

$cache_id = implode('|', array(
'imp_avatar_email',
$type,
$this->_email
));

if ($url = $cache->get($cache_id, 0)) {
try {
return $pack->unpack($url);
} catch (Horde_Pack_Exception $e) {}
}

foreach ($conf['contactsimage']['backends'] as $val) {
if (class_exists($val)) {
$backend = new $val();
if (($backend instanceof $type) &&
($url = $backend->$func($this->_email))) {
$cache->set(
$cache_id,
$pack->pack($url),
$this->cache_timeout
);
return $url;
}
}
Expand Down

0 comments on commit 20c98f3

Please sign in to comment.