1

Aug

Filed in Code, PHP |

One big thing with large sites is optimization, and a major factor in most sites is SQL. In the end, all optimization methods begin, and most likely end, with a caching solution. While disk caching is not the only solution, in my opinion, for most situations, it is the best solution.

With Nibbits I was in need of such a solution. Nibbits itself is extremely optimized in the code and the SQL queries, but even the most optimized code still can only handle so much load. So today, with about 30 minutes of spare time, I whipped up a quick standard disk caching library.

As always, you can grab the source for my PHP disk caching class.

The class follows the standard calls you see in nearly every major caching system, get and set.

$c = new cache();
if (!$data = $c->get('group', 'unique id'))
{
$data = 'this was cached at '.date();
$c->set('group', 'unique id', 10, $data);
}

There are two constants the source uses and you will most likely want to set:

CACHE_DIRECTORY - the absolute path to the directory where cached data should reside
CACHE_PREFIX - the prefix the class should use on files in this directory

View Comments Responses to "SQL Optimization with Disk Caching in PHP"

Subscribe to this topic with RSS or get the Trackback URL

Leave A Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)

Note: Comments moderation may be active so there is no need to resubmit your comment.
blog comments powered by Disqus