Avoid tampering cache file by escaping all keys and values
- changing all $modx->db->escape to $this->escapeSingleQuotes/$this->escapeDoubleQuotes
- reformatted code for better readability