Basically, I am implementing own cache system. Ideally, it'll look like this:
$CACHE->start($name);
//CODE
$CACHE->end();
But that is a holy grail that I do not hope to find. Basically, the $CACHE->start() checks if cache is a hit or a miss, and whether it is a hit, it skips the //CODE until $CACHE->end().
The best I have come so far, is:
if ($CACHE->start($name)) {
//CODE
}
$CACHE->end();
Since PHP supports anonymous functions, I was thinking of:
$CACHE->make($name, function() {
//CODE
});
But this code has a problem that code is not in the same variable scope. Any chance to bypass that?
Update: I have since switched to ruby, which allows to pass the block to a function, being perfect for this task.
Zend Framework includes a cache that skips
$cache->end()by assuming the remainder of the page is part of the cached content.It doesn't fit all use-cases though.
(A modified version of my comment)