Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

has partial caching become buggy?


Go to End


17 Posts   5744 Views

Avatar
mikeyc7m

Community Member, 19 Posts

12 February 2015 at 8:28pm

I like caching, it's good. But in 3.1.9 it's not working properly.

This works fine, the $LastEdited and $Now dates don't change:

$LastEdited
<% cached %>
$Now
<% end_cached %>

But this doesn't work, it isn't caching because the $Now date keeps changing:

$LastEdited
<% cached LastEdited %>
$Now
<% end_cached %>

In fact it seems the <% cached %> tag doesn't support any parameters at all.

Avatar
martimiz

Forum Moderator, 1391 Posts

13 February 2015 at 1:35am

Hmm, I couldn't reproduce that. Tested on 3.1.8, then updated to 3.1.9 and $Now didn't change for me using your second example... Have you tried this on a default install?

Note: I wasn't even sure that you could add parameters without defining a name, like in <% cached 'test', LastEdited %>

Avatar
mikeyc7m

Community Member, 19 Posts

16 February 2015 at 1:02pm

Edited: 16/02/2015 1:44pm

I'm not getting any caching except the default 10 minutes. I thought it might be an ajax specific issue but no.
Sad panda.

Avatar
mikeyc7m

Community Member, 19 Posts

16 February 2015 at 5:55pm

It is only respecting "if" and "unless" flags, so it seems it can only compare boolean values.

<% cached unless 1==2 %>

Unfortunately I need to use $LastEdited which can't return any boolean equivalent because I'm comparing to page views. I'll have to use a horrid write-on-pageview method to return a boolean.

Avatar
ee

Community Member, 7 Posts

24 June 2015 at 9:29pm

Did anyone find a solution to this?

I have the exact problem - simply changing

<% cached "latestblogarticles", $List("BlogArticle").count() %>
to
<% cached %>
results in the block being cached. But I need the cache to check if the amount of items has changed.

Thanks

Avatar
ee

Community Member, 7 Posts

30 June 2015 at 3:57am

Can anyone confirm if partial caching actually works when you give the item a name and use parameters for example

<% cached "latestblogarticles", $List("BlogArticle").count() %>

If not, where would I report this major bug. This is for the latest version - 3.1.13

Any help/advice much appreciated. Thanks

Avatar
Devlin

Community Member, 344 Posts

30 June 2015 at 7:58pm

I don't really see the issue, but I can confirm that this works as intended.

<% cached 'SiteTree', $ID, $List("SiteTree").count() %>
$Now // renewed at change at SiteTree.Count
<% end_cached %>

<% cached 'SiteTree', $ID, $List("SiteTree").max('LastEdited') %>
$Now // renewed at change in SiteTree
<% end_cached %>

$LastEdited
<% cached %>
$Now // now doesn't change (-- unless cache expires)
<% end_cached %>

$LastEdited
<% cached LastEdited %>
$Now // renewed at change in current DataObject
<% end_cached %>

Avatar
ee

Community Member, 7 Posts

30 June 2015 at 8:57pm

Edited: 30/06/2015 8:58pm

Hi Devlin

Right, I have just created a brand new fresh install of silverstripe 3.1.13 and stripped out the simple theme page.ss to just the following

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<% cached 'SiteTree', $ID, $List("SiteTree").count() %>
$Now // renewed at change at SiteTree.Count
<% end_cached %>


<% cached 'SiteTree', $ID, $List("SiteTree").max('LastEdited') %>
$Now // renewed at change in SiteTree
<% end_cached %>

</body>
</html>

I load the page and see two lots of todays date and time. I then refresh the page and both date/times are updated to show the current time. This is incorrect as no pages have been created/removed or changed. ???

I then created the "silverstripe-cache" folder and this has made no difference.

Have I missed something that should go in a config file to say use partial caching?

Thanks in advance.

Go to Top