I (like a number of members from a quick search of the Forums and Google) have been having intermittent issues whereby I would get a number of PHP errors dumped at the top of most pages stating something like (borrowing error content from http://forum.opencart.com/viewtopic.php ... he#p131780):
Code: Select all
PHP Warning: unlink(/home/julugu/public_html/system/cache/cache.category.38.2.0.1295512099) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/julugu/public_html/system/library/cache.php on line 14
Code: Select all
public function __construct() {
$files = glob(DIR_CACHE . 'cache.*');
if ($files) {
foreach ($files as $file) {
$time = substr(strrchr($file, '.'), 1);
if ($time < time()) {
if (file_exists($file)) {
@unlink($file);
}
}
}
}
}
As much as this is a sub-optimal solution, I have modified this function of the cache.php file, in my own install, as follows:
Code: Select all
public function __construct() {
$files = glob(DIR_CACHE . 'cache.*');
if ($files) {
foreach ($files as $file) {
$time = substr(strrchr($file, '.'), 1);
if ($time < time() && file_exists($file)) {
@touch($file);
@unlink($file);
}
}
}
}
I also found that the get() function pulls an array of all cache files matching the specified key, but, in the case where two cache files, with the same key, but different expiry stamps were found, it would return the oldest of the two (rather than the youngest). To resolve this I added a call to array_reverse() to flip the sorted order of the returned files and resolve this, although a more permanent solution (where the older matching file(s) were deleted) might be in order.
And further, I added functionality to use file_get_contents() and file_put_contents() (where available) for the inserting and retrieval of data into and from the cache files.
I have attached the modified cache.php file (renamed cache.txt) for reference, should anyone want to do so.