memcached can set expire
This commit is contained in:
parent
91d0652476
commit
da37497a38
@ -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