Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the time to live (TTL) for a memcached key be set to infinite?

Tags:

php

memcached

I have implemented memcache in my PHP-MySQL based app and it gets updated regularly from a backend process.

Due to this some data is conflicting with the expiration time and other backend processes, so I came up with a solution but for that I would have to make the TTL = infinite.

like image 765
Himanshu Avatar asked May 17 '11 07:05

Himanshu


2 Answers

Easy - just write 0 there.

expire

Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).

like image 51
OZ_ Avatar answered Sep 18 '22 12:09

OZ_


You can set the TTL to 0, which means that it should 'never' expire.

But remember that it will never really be infinite. The data is stored in memory and will be lost under some circumstances, the most obvious being the server being rebooted. :)

You should always have the possibility to reconstruct that data when the memcache fails.

More details to be found here.

like image 29
GolezTrol Avatar answered Sep 18 '22 12:09

GolezTrol