Jump to:

22975 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » partial caching issue with LastEdited

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: 198 Views
  • BenWu
    Avatar
    Community Member
    87 Posts

    partial caching issue with LastEdited Link to this post

    Hello,

    inside the SS template i got

    <% cached Children.max(LastEdited) %>
    <% loop Children %>
    <h3>$Title</h3>
    $Thumbnail
    <% end_loop %>
    <% end_cached %>

    Each sub page got a thumb-nail image attached. In CMS, if i change the thumb-nail image via the UploadField, click 'Save and Publish', the 'LastEdited' field doesn't change (probably because i did not change the content of it?) and thus the change is not reviewed on the front pages. Is this a SS bug that the field 'LastEdited' not changed even though i click on the 'Save and Publish" ?

    How to get around this partial caching problem?

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: partial caching issue with LastEdited Link to this post

    One solution is to subclass Image, then your page can have a relation to that class instead of a relation to image. So:

    class MyImage extends Image {
    }

    class MyPage extends Page {
    public static $has_one = array(
    'Image'=>'MyImage'
    );
    }

    Then in your template, you can do <% cached Children.Max(LastEdited), List(MyImage).Max(LastEdited) %>

    Hope this helps

  • BenWu
    Avatar
    Community Member
    87 Posts

    Re: partial caching issue with LastEdited Link to this post

    I guess List(MyImage).Max(LastEdited) will force SS to search all 'MyImage' objects in database and get the lastest LastEdited field value as part of the cache key.

    The problem is: MyPage and MyImage is a many-many relation. The LastEdited field will not work because the image itself is not edited. the image is linked to another page. we just built a new link.

    I guess I have to write a function to find out all the related images of the sub page and work out a key, and pass that function to SS template

    class MySubPage {
    static $many_many = array('Images' =>'MyImage')
    }

    }

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: partial caching issue with LastEdited Link to this post

    Yep, you can calculate the cache key in your controller: http://doc.silverstripe.org/framework/en/trunk/reference/partial-caching#cache-key-calculated-in-controller

    I don't really know the best way to approach it, though. Perhaps you could fetch all records from the join table (e.g 'MyImage_MySubPage'), implode it to a string and md5 hash it?

  • BenWu
    Avatar
    Community Member
    87 Posts

    Re: partial caching issue with LastEdited Link to this post

    That's what i thought, but then how do you 'aggregate' all the md5 strings? using max,min,avg, or sum is not going to work. I think I just concatenate all the md5 string together to build a large key.

    198 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.