Check thread cache size before writing to memcache.

This commit is contained in:
Retro_Guy 2024-05-13 16:35:58 -07:00
parent ee782e3a63
commit d540ccd0ca
1 changed files with 25 additions and 3 deletions

View File

@ -95,11 +95,23 @@ function thread_cache_load($group)
}
if ($memcacheD) {
$key = 'thread_cache-' . $group;
$add_thread = gzcompress(serialize($headers), 9);
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
$thread_bytes = strlen($add_thread);
$too_big = false;
if($thread_bytes < 1024000) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
} else {
$nicole = false;
$too_big = true;
}
if ($nicole && $enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache miss) Wrote $key (" . strlen($add_thread) . " bytes)", FILE_APPEND);
}
if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
}
}
return ($headers);
}
@ -142,13 +154,23 @@ function thread_cache_save($headers, $group)
$key = 'thread_cache-' . $group;
$del = $memcacheD->delete($key);
$add_thread = gzcompress(serialize($headers), 9);
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
$thread_bytes = strlen($add_thread);
$too_big = false;
if($thread_bytes < 1024000) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
} else {
$too_big = true;
$nicole = false;
}
if ($enable_memcache_logging) {
if ($del) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Deleted $key", FILE_APPEND);
}
if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Wrote $key (" . strlen($add_thread) . " bytes)", FILE_APPEND);
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Wrote $key (" . $thread_bytes . " bytes)", FILE_APPEND);
}
if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
}
}
}