Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » how to uncache fields within condition structures ?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1097 Views
  • Kent
    Avatar
    Community Member
    5 Posts

    how to uncache fields within condition structures ? Link to this post

    example:

    <% cached 'getAllNews', Aggregate(News).Max(LastEdited) %>
    <% if getAllNews %>
    <ul>
    <% control getAllNews %>
    <li><a href="$Link" title="$Title">$Title</a></li>
    // I wanna uncache TotalLike field like this
    <% uncached %><li><a href="javascript:like(this)" title="Like">$TotalLike</a></li><% end_uncached %>
    <% end_control %>
    </ul>
    <% end_if %>
    <% end_cached %>

  • Kent
    Avatar
    Community Member
    5 Posts

    Re: how to uncache fields within condition structures ? Link to this post

    nobody help me ..

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: how to uncache fields within condition structures ? Link to this post

    In http://doc.silverstripe.org/sapphire/en/reference/partial-caching somewhere it states:

    Currently cached blocks can not be contained within if or control blocks. The template engine will throw an error letting you know if you've done this. You can often get around this using aggregates.

    I guess the same goes for uncached blocks, so I don't think it can be done this way.

  • Kent
    Avatar
    Community Member
    5 Posts

    Re: how to uncache fields within condition structures ? Link to this post

    I understand this, but as you see, in my project, used partial-caching and I set cache life time is 300s = 5 minutes, some fields cant not be cached such as Like, when logged user click on Like button, this number will increase 1 by javascript, Like button will become unclickable, then send a request to update database, but with in ***5 minutes***, if user refesh page (F5), the number of Like will go back beacause it was cached before, and Like button still clickable.
    I hope this feature will be implement into SS in the future

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: how to uncache fields within condition structures ? Link to this post

    You could use the # of likes as part of the cache key. So rather than using LastEdited define your own key (http://doc.silverstripe.org/sapphire/en/reference/partial-caching#cache-key-calculated-in-controller) which uses page id + likes + last edited to generate a unique key.

    Or you could load the like values using ajax which is fired off when the page loads. That request would return something like whether the user has liked it and the count of likes. Though looking at your example I can't see how you're passing back whether the user has voted or note.

    1097 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.