Current location - Trademark Inquiry Complete Network - Trademark inquiry - Can PHP get the expiration time of the key in memcache?
Can PHP get the expiration time of the key in memcache?
Memcached data expiration mechanism delays expiration

Internally, it does not monitor whether the record is out of date, but checks the timestamp of the record when checking whether the record is out of date. This technique is called delayed expiration. Therefore, memcached does not spend CPU time on expiration monitoring, in other words, it cannot detect the expiration time of a key.

You can use a more stupid method:

Define(' MEM _ timeout',1800);

$ memKey = " testkey

$val =' This is the test value';

mem_set($key,$ val); //Call

Function mem_set($key, $ val) (

$ memcache-& gt; Set($memKey, $val, 0, MEM _ timeout);

//Add a recording time when calling set.

$ memcache-& gt; set('TIME_ '。 $memKey,time(),0,MEM _ TIME _ OUT);

}

Function mem_get($key, $is_time = false) {

$memKey = $is_time? Time _'. $ key:$ key;

$ val = $ memcache-& gt; get($ key);

If ($is_time) {

$ val = MEM _ timeout-(time ()-$ val);

}

Return $ val

}