A few questions about PHP memcache

1)
I understand that I can call it

$memcache_obj = memcache_connect('memcache_host', 11211);

in the header files of my site without affecting pages that do not use memcache but how about this

$memcache->connect('127.0.0.1', 11211);

Should this be called on page by page?


2)
what if the server does not have enough memory to write new caches, and memcache tries to save the cache?


3)
I know that keys can have up to 30 days of life. Is there a way to reset all keys from memory, especially useful for the testing phase?

4)
Also this code, the first variable is connected, for example, if I have 5 sections on the page that add / update / delete from memcache, do I need to start this connection every time, or can I connect 1 time and do everything to load the page?

memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30)

5) -, , php-?

+3
3
+8

, , :

2) , 1 ( ) , memcache FALSE. FALSE, - .

3) > 30 (TTL). TTL TTL. , - ( ):

$ttl = 60*60*24*60; // 60 days
$newTTL = time()+$ttl;
memcache_set($memcache_obj, 'cache_key', 'some data', 0, $newTTL)

5) PHP, memory_get_usage() , . Memcache , getStats() .

+3

Source: https://habr.com/ru/post/1714102/


All Articles