Ok, I managed to solve the PHx caching problem (although the solution isn’t exactly clean, as usual

)
I was building an archive page for my web with Ditto/Reflect and I wanted to use pagination. And pagination means that snippet can’t be cached. That’s when the problem with redundant PHx mysql requests returned. My page needed again a lot of sql queries and when I checked the log, PHx was guilty. So I opened PHx plugin and found out, that PHx has its own cache however it doesn’t work for some reason. It is a simple array which should contain already loaded snippets. However stored items always disappear and have to be fetched again. I don’t understand much how PHx or generally plugins work so I wasn’t able to find the real reason. Or maybe I just missed something. However I did a simple thing to fix it. I replaced PHx cache ($PHx->cache["cm"]) with array stored in $modx->vars. It’s working now very well, snippets are being cached correctly and I no more need dozens of queries.
This is the final code (/assets/plugins/phx/phx.parser.class.inc.php around line 290)
<?php
if (!is_array($modx->vars["cm"])) $modx->vars["cm"] = array();
if (!array_key_exists($modifier_cmd[$i], $modx->vars["cm"])) {
$sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='phx:" . $modifier_cmd[$i] . "';";
$result = $modx->dbQuery($sql);
if ($modx->recordCount($result) == 1) {
$row = $modx->fetchRow($result);
$cm = $modx->vars["cm"][$modifier_cmd[$i]] = $row["snippet"];
$this->Log(" |--- DB -> Custom Modifier");
} else if ($modx->recordCount($result) == 0){ // If snippet not found, look in the modifiers folder
$filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/'.$modifier_cmd[$i].'.phx.php';
if (@file_exists($filename)) {
$file_contents = @file_get_contents($filename);
$file_contents = str_replace('<'.'?php', '', $file_contents);
$file_contents = str_replace('?'.'>', '', $file_contents);
$file_contents = str_replace('<?', '', $file_contents);
$cm = $modx->vars["cm"][$modifier_cmd[$i]] = $file_contents;
$this->Log(" |--- File ($filename) -> Custom Modifier");
}
}
} else {
$cm = $modx->vars["cm"][$modifier_cmd[$i]];
$this->Log(" |--- Cache -> Custom Modifier");
}?>
PHx version 2.1.3