Like many other users, I always used "disk" as the cache method in the config. I wanted to try memcache just for testing. It seems as it turns out, there is a seemingly better version of that called "memcached", so I installed it on my test server, and switched my config to this.
and removed the other options that are long dead and no longer anything. There are only 2 reasonable options, disk or memcached, so here is an updated cache.php file
You can google how to adjust the amount of RAM to allow it to use. I own my server, so I have 32gb allocated, and am noticing alot of improvement over disk. You dont have to go that high with the RAM, but I have plenty of RAM and only noticed about 1.5gb used for this Just wanted to post my findings. Time will tell, but so far it seems much better
// Caching Configuration
$site_config["cache_type"] = "memcached"; // Cache type (disk or memcached. Must install memcached on your server to use)
$site_config["cache_memcached_host"] = "localhost"; // Memcache host
$site_config["cache_memcached_port"] = 11211; // Memcache port
$site_config['cache_dir'] = getcwd().'/cache/diskcache'; // Disk cache directory (chmod 777)and removed the other options that are long dead and no longer anything. There are only 2 reasonable options, disk or memcached, so here is an updated cache.php file
<?php
$GLOBALS["TTCache"] = new TTCache;
class TTCache {
private $cachedir;
private $type;
private $obj;
function __construct() {
GLOBAL $site_config;
$this->cachedir = rtrim($site_config["cache_dir"], '/') . '/';
$this->type = strtolower(trim($site_config["cache_type"]));
switch ($this->type) {
case "memcached":
// Check for extension
if (!class_exists('Memcached')) {
error_log("Memcached extension not installed, falling back to disk.");
$this->type = "disk";
break;
}
$this->obj = new Memcached();
$this->obj->addServer(
$site_config["cache_memcached_host"],
$site_config["cache_memcached_port"]
);
// Test connection
$stats = $this->obj->getStats();
if (empty($stats)) {
error_log("Memcached server not reachable, falling back to disk.");
$this->type = "disk";
}
break;
default:
$this->type = "disk";
}
}
function Set($var, $val, $expire = 0) {
GLOBAL $site_config;
if ($expire == 0) return;
$var = $site_config['SITENAME'] . "_" . $var;
switch ($this->type) {
case "memcached":
return $this->obj->set($var, $val, $expire);
case "disk":
$cache_file = $this->cachedir . md5($var) . '.cache';
if (file_put_contents($cache_file, serialize($val)) === false) {
throw new Exception("Failed to write cache file: " . $cache_file);
}
touch($cache_file, time() + $expire);
return true;
}
}
function Delete($var) {
GLOBAL $site_config;
$var = $site_config['SITENAME'] . "_" . $var;
switch ($this->type) {
case "memcached":
return $this->obj->delete($var);
case "disk":
$cache_file = $this->cachedir . md5($var) . '.cache';
if (file_exists($cache_file) && !unlink($cache_file)) {
throw new Exception("Failed to delete cache file: " . $cache_file);
}
return true;
}
}
function Get($var, $expire = 0) {
GLOBAL $site_config;
if ($expire == 0) return false;
$var = $site_config['SITENAME'] . "_" . $var;
switch ($this->type) {
case "memcached":
$result = $this->obj->get($var);
if ($this->obj->getResultCode() === Memcached::RES_NOTFOUND) {
return false;
}
return $result;
case "disk":
$cache_file = $this->cachedir . md5($var) . '.cache';
if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $expire) {
return unserialize(file_get_contents($cache_file));
}
return false;
}
}
}
// Cached MySQL Functions
function get_row_count_cached($table, $suffix = "") {
GLOBAL $TTCache;
$query = "SELECT COUNT(*) FROM $table $suffix";
$cache = "get_row_count/" . sha1($query);
if (($ret = $TTCache->Get($cache, 300)) === false) {
$res = SQL_Query_exec($query);
$row = mysqli_fetch_row($res);
$ret = $row[0];
$TTCache->Set($cache, $ret, 300);
}
return $ret;
}
function SQL_Query_exec_cached($query, $cache_time = 300, $cache_blank = 1) {
GLOBAL $TTCache;
$cache = "queries/" . sha1($query);
if (($rows = $TTCache->Get($cache, $cache_time)) === false) {
$res = SQL_Query_exec($query);
$rows = array();
while ($row = mysqli_fetch_assoc($res)) {
$rows[] = $row;
}
if (count($rows) || $cache_blank) {
$TTCache->Set($cache, $rows, $cache_time);
}
}
return count($rows) ? $rows : false;
}You can google how to adjust the amount of RAM to allow it to use. I own my server, so I have 32gb allocated, and am noticing alot of improvement over disk. You dont have to go that high with the RAM, but I have plenty of RAM and only noticed about 1.5gb used for this Just wanted to post my findings. Time will tell, but so far it seems much better
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2026-04-11 17:04:16