Merge pull request #16364 from frederic34/memcacheexpire
memcached can set expire
This commit is contained in:
commit
c9f67b27b2
@ -52,10 +52,10 @@ function societe_prepare_head(Societe $object)
|
|||||||
|
|
||||||
if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) {
|
if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) {
|
||||||
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) {
|
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
|
||||||
|
|
||||||
//$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
|
//$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
|
||||||
$nbContact = 0;
|
$nbContact = 0;
|
||||||
|
// Enable caching of thirdrparty count Contacts
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
$cachekey = 'count_contacts_thirdparty_'.$object->id;
|
$cachekey = 'count_contacts_thirdparty_'.$object->id;
|
||||||
$dataretrieved = dol_getcache($cachekey);
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ function societe_prepare_head(Societe $object)
|
|||||||
$nbContact = $obj->nb;
|
$nbContact = $obj->nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_setcache($cachekey, $nbContact); // If setting cache fails, this is not a problem, so we do not test result.
|
dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
}
|
}
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
|
||||||
@ -129,7 +129,15 @@ function societe_prepare_head(Societe $object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) {
|
if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) {
|
||||||
$nbNote = 0;
|
$nbProject = 0;
|
||||||
|
// Enable caching of thirdrparty count projects
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
|
$cachekey = 'count_projects_thirdparty_'.$object->id;
|
||||||
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
|
|
||||||
|
if (!is_null($dataretrieved)) {
|
||||||
|
$nbProject = $dataretrieved;
|
||||||
|
} else {
|
||||||
$sql = "SELECT COUNT(n.rowid) as nb";
|
$sql = "SELECT COUNT(n.rowid) as nb";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
|
$sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
|
||||||
$sql .= " WHERE fk_soc = ".$object->id;
|
$sql .= " WHERE fk_soc = ".$object->id;
|
||||||
@ -137,14 +145,16 @@ function societe_prepare_head(Societe $object)
|
|||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
$nbNote = $obj->nb;
|
$nbProject = $obj->nb;
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
|
}
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
|
||||||
$head[$h][1] = $langs->trans("Projects");
|
$head[$h][1] = $langs->trans("Projects");
|
||||||
if ($nbNote > 0) {
|
if ($nbProject > 0) {
|
||||||
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
|
||||||
}
|
}
|
||||||
$head[$h][2] = 'project';
|
$head[$h][2] = 'project';
|
||||||
$h++;
|
$h++;
|
||||||
@ -271,10 +281,9 @@ function societe_prepare_head(Societe $object)
|
|||||||
if ($user->socid == 0) {
|
if ($user->socid == 0) {
|
||||||
// Notifications
|
// Notifications
|
||||||
if (!empty($conf->notification->enabled)) {
|
if (!empty($conf->notification->enabled)) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
|
||||||
|
|
||||||
$nbNotif = 0;
|
$nbNotif = 0;
|
||||||
// Enable caching of thirdrparty count notifications
|
// Enable caching of thirdrparty count notifications
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
$cachekey = 'count_notifications_thirdparty_'.$object->id;
|
$cachekey = 'count_notifications_thirdparty_'.$object->id;
|
||||||
$dataretrieved = dol_getcache($cachekey);
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
if (!is_null($dataretrieved)) {
|
if (!is_null($dataretrieved)) {
|
||||||
@ -290,7 +299,7 @@ function societe_prepare_head(Societe $object)
|
|||||||
} else {
|
} else {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
dol_setcache($cachekey, $nbNotif); // If setting cache fails, this is not a problem, so we do not test result.
|
dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
}
|
}
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
|
||||||
@ -318,17 +327,28 @@ function societe_prepare_head(Societe $object)
|
|||||||
$head[$h][2] = 'note';
|
$head[$h][2] = 'note';
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
// Attached files
|
// Attached files and Links
|
||||||
|
$totalAttached = 0;
|
||||||
|
// Enable caching of thirdrparty count attached files and links
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
|
$cachekey = 'count_attached_thirdparty_'.$object->id;
|
||||||
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
|
if (!is_null($dataretrieved)) {
|
||||||
|
$totalAttached = $dataretrieved;
|
||||||
|
} else {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
|
||||||
$upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
|
$upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
|
||||||
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
|
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
|
||||||
$nbLinks = Link::count($db, $object->element, $object->id);
|
$nbLinks = Link::count($db, $object->element, $object->id);
|
||||||
|
$totalAttached = $nbFiles + $nbLinks;
|
||||||
|
dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
|
}
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
|
||||||
$head[$h][1] = $langs->trans("Documents");
|
$head[$h][1] = $langs->trans("Documents");
|
||||||
if (($nbFiles + $nbLinks) > 0) {
|
if (($totalAttached) > 0) {
|
||||||
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
|
||||||
}
|
}
|
||||||
$head[$h][2] = 'document';
|
$head[$h][2] = 'document';
|
||||||
$h++;
|
$h++;
|
||||||
@ -337,10 +357,9 @@ function societe_prepare_head(Societe $object)
|
|||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
|
||||||
$head[$h][1] = $langs->trans("Events");
|
$head[$h][1] = $langs->trans("Events");
|
||||||
if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
|
if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
|
||||||
|
|
||||||
$nbEvent = 0;
|
$nbEvent = 0;
|
||||||
// Enable caching of thirdrparty count actioncomm
|
// Enable caching of thirdrparty count actioncomm
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
$cachekey = 'count_events_thirdparty_'.$object->id;
|
$cachekey = 'count_events_thirdparty_'.$object->id;
|
||||||
$dataretrieved = dol_getcache($cachekey);
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
if (!is_null($dataretrieved)) {
|
if (!is_null($dataretrieved)) {
|
||||||
@ -356,7 +375,7 @@ function societe_prepare_head(Societe $object)
|
|||||||
} else {
|
} else {
|
||||||
dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
|
dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
|
||||||
}
|
}
|
||||||
dol_setcache($cachekey, $nbEvent); // If setting cache fails, this is not a problem, so we do not test result.
|
dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
}
|
}
|
||||||
|
|
||||||
$head[$h][1] .= '/';
|
$head[$h][1] .= '/';
|
||||||
|
|||||||
@ -2450,9 +2450,17 @@ function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64,
|
|||||||
function getArrayOfSocialNetworks()
|
function getArrayOfSocialNetworks()
|
||||||
{
|
{
|
||||||
global $conf, $db;
|
global $conf, $db;
|
||||||
|
|
||||||
|
$socialnetworks = array();
|
||||||
|
// Enable caching of array
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
|
||||||
|
$cachekey = 'socialnetworks_' . $conf->entity;
|
||||||
|
$dataretrieved = dol_getcache($cachekey);
|
||||||
|
if (!is_null($dataretrieved)) {
|
||||||
|
$socialnetworks = $dataretrieved;
|
||||||
|
} else {
|
||||||
$sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks";
|
$sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks";
|
||||||
$sql .= " WHERE entity=".$conf->entity;
|
$sql .= " WHERE entity=".$conf->entity;
|
||||||
$socialnetworks = array();
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
while ($obj = $db->fetch_object($resql)) {
|
while ($obj = $db->fetch_object($resql)) {
|
||||||
@ -2465,6 +2473,9 @@ function getArrayOfSocialNetworks()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dol_setcache($cachekey, $socialnetworks); // If setting cache fails, this is not a problem, so we do not test result.
|
||||||
|
}
|
||||||
|
|
||||||
return $socialnetworks;
|
return $socialnetworks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,10 +61,11 @@ $shmoffset = 1000; // Max number of entries found into a language file. If too l
|
|||||||
*
|
*
|
||||||
* @param string $memoryid Memory id of shared area
|
* @param string $memoryid Memory id of shared area
|
||||||
* @param mixed $data Data to save. It must not be a null value.
|
* @param mixed $data Data to save. It must not be a null value.
|
||||||
|
* @param int $expire ttl in seconds, 0 never expire
|
||||||
* @return int <0 if KO, 0 if nothing is done, Nb of bytes written if OK
|
* @return int <0 if KO, 0 if nothing is done, Nb of bytes written if OK
|
||||||
* @see dol_getcache()
|
* @see dol_getcache()
|
||||||
*/
|
*/
|
||||||
function dol_setcache($memoryid, $data)
|
function dol_setcache($memoryid, $data, $expire = 0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
$result = 0;
|
$result = 0;
|
||||||
@ -85,7 +86,7 @@ function dol_setcache($memoryid, $data)
|
|||||||
|
|
||||||
$memoryid = session_name() . '_' . $memoryid;
|
$memoryid = session_name() . '_' . $memoryid;
|
||||||
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
|
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
|
||||||
$dolmemcache->add($memoryid, $data); // This fails if key already exists
|
$dolmemcache->add($memoryid, $data, $expire); // This fails if key already exists
|
||||||
$rescode = $dolmemcache->getResultCode();
|
$rescode = $dolmemcache->getResultCode();
|
||||||
if ($rescode == 0) {
|
if ($rescode == 0) {
|
||||||
return count($data);
|
return count($data);
|
||||||
@ -104,7 +105,7 @@ function dol_setcache($memoryid, $data)
|
|||||||
|
|
||||||
$memoryid = session_name() . '_' . $memoryid;
|
$memoryid = session_name() . '_' . $memoryid;
|
||||||
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
|
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
|
||||||
$result = $dolmemcache->add($memoryid, $data); // This fails if key already exists
|
$result = $dolmemcache->add($memoryid, $data, false, $expire); // This fails if key already exists
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return count($data);
|
return count($data);
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +113,7 @@ function dol_setcache($memoryid, $data)
|
|||||||
}
|
}
|
||||||
} elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead.
|
} elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead.
|
||||||
// Using shmop
|
// Using shmop
|
||||||
$result = dol_setshmop($memoryid, $data);
|
$result = dol_setshmop($memoryid, $data, $expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@ -226,9 +227,10 @@ function dol_listshmop()
|
|||||||
*
|
*
|
||||||
* @param int $memoryid Memory id of shared area ('main', 'agenda', ...)
|
* @param int $memoryid Memory id of shared area ('main', 'agenda', ...)
|
||||||
* @param string $data Data to save. Must be a not null value.
|
* @param string $data Data to save. Must be a not null value.
|
||||||
|
* @param int $expire ttl in seconds, 0 never expire
|
||||||
* @return int <0 if KO, 0=Caching not available, Nb of bytes written if OK
|
* @return int <0 if KO, 0=Caching not available, Nb of bytes written if OK
|
||||||
*/
|
*/
|
||||||
function dol_setshmop($memoryid, $data)
|
function dol_setshmop($memoryid, $data, $expire)
|
||||||
{
|
{
|
||||||
global $shmkeys, $shmoffset;
|
global $shmkeys, $shmoffset;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user