Partial cacheing: http://doc.silverstripe.org/sapphire/en/reference/partial-caching
The uncached tag doesn't seem to work when used inside a layout to cancel a cached tag in the main Page.ss. Or am I doing something wrong?
I have a cached tag in tutorial/templates/Page.ss and an uncached tag in tutorial/templates/Layout/Page.ss, but he contents of the uncached tag are still cached.
There is a workaround, which is to close the cached tag before $Layout and open another cached tag inside the layout file if necessary, then a nested uncached tag works.
Maybe it's good practice never to enclose $Layout in a cached tag, and to consider all layouts on a case-by-case basis. Whatever, I don't think the behaviour I'm seeing is intended. I can't see any reference to this issue in trac.
This is how to reproduce the problem using the tutorial theme. Or is the problem that I've misunderstood how the cached and uncached tags are used?
_config.php
SS_Cache::set_cache_lifetime('any', 24 * 60 * 60);
Page.php
function CurrentDateTime() {
return date('Y-m-d H:i:s');
}
Page.ss
Note the cached tag wrapped around the $Layout
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
<head>
<% base_tag %>
<link rel="stylesheet" type="text/css" href="tutorial/css/layout.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/typography.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/form.css" />
</head>
<body>
<div id="Main">
<% cached 'Outer', ID, LastEdited, SiteConfig.LastEdited %>
<% include CacheStats %>
$Layout
<% end_cached %>
</div>
$SilverStripeNavigator
</body>
</html>
Layout/Page.ss
<h1>Inside layout</h1>
<% include CacheStats %>
Includes/CacheStats.ss
Note the uncached tag wrapped around the first two timestamps in the table
<div id="ContentContainer">
<h2>Cache Stats:</h2>
<table>
<% uncached %>
<tr>
<td>Now</td>
<td>$CurrentDateTime</td>
</tr>
<tr>
<td>LastEdited</td>
<td>$LastEdited</td>
</tr>
<% end_uncached %>
<tr>
<td>Cached</td>
<td>$CurrentDateTime</td>
</tr>
</table>
</div>
The page type is used to create a page in the CMS. Before viewing the published page, delete all files in silverstripe-cache/cache
The first time the page is viewed, both sets of times are the same.
The second time the page is viewed, the two values of Now are different, which should never happen. All times inside the layout are the same as before, they have been cached, even though they are in a cached tag.
Cache Stats:
Now 2011-09-26 18:07:42
LastEdited 2011-09-25 21:59:32
Cached 2011-09-26 18:07:18
Inside layout
Cache Stats:
Now 2011-09-26 18:07:18
LastEdited 2011-09-25 21:59:32
Cached 2011-09-26 18:07:18
The Now value should always show the current time, because it is uncached, right?