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.

General Questions /

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

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

Partial Caching - Understanding the Concepts


Go to End


19 Posts   8041 Views

Avatar
ee

Community Member, 7 Posts

20 June 2015 at 2:30am

Edited: 20/06/2015 2:31am

I have started a new site in version 3.1.13 and am struggling to understand why my partial caching is not working.

In a previous silverstripe version (3.0) it used to save cache files in the /silverstripe-cache/cache with file names such as zend_cache----cacheblockXXXXX but now in v 3.1.13 it seems to create user named folders and doesn't seem to be generating the zend_cache----cacheblock files in any of the subfolders.

I have created the following function in page.php where BlogArticle is a dataobject

public function LatestBlogArticles($limit = 3){
     $b = DataObject::get('BlogArticle', '', '', '', $limit);
     return $b;
}

On my HomePage.ss I have the following:

<ul class="blog-posts">
    <% cached "latestblogarticles", $List("BlogArticle").count() %>
        <% loop LatestBlogArticles %>
            <li>
				$Title
                <datetime>$Date.format(F d, Y)</datetime>  
            </li>
         <% end_loop %>
    <% end_cached %>
</ul>

Running ?showqueries=1 shows the following queries
...
SHOW TABLES LIKE 'BlogArticle' 0.0008s
SHOW FULL FIELDS IN "BlogArticle" 0.0024s
SELECT DISTINCT "ClassName" FROM "BlogArticle" 0.0004s
SELECT DISTINCT count(DISTINCT "BlogArticle"."ID") AS "0" FROM "BlogArticle" 0.0004s
SELECT DISTINCT "BlogArticle"."ClassName", "BlogArticle"."Created", "BlogArticle"."LastEdited", "BlogArticle"."Title", "BlogArticle"."Abstract", "BlogArticle"."Content", "BlogArticle"."URLSegment", "BlogArticle"."Date", "BlogArticle"."MetaTitle", "BlogArticle"."MetaDesc", "BlogArticle"."Active", "BlogArticle"."ArticleImageID", "BlogArticle"."ID", CASE WHEN "BlogArticle"."ClassName" IS NOT NULL THEN "BlogArticle"."ClassName" ELSE 'BlogArticle' END AS "RecordClassName" FROM "BlogArticle" LIMIT 3 0.0043s
...

You would expect with caching if you refresh the page only the SELECT DISTINCT count(DISTINCT "BlogArticle"."ID") query would execute as the number of BlogArticles has not changed. But that is not the case, the above queries are still running and I see no generated cache files.

Can anyone please help me on how caching should work in this example? The documentation is not very helpful for beginners!

Thanks

Avatar
Pyromanik

Community Member, 419 Posts

23 June 2015 at 8:59pm

Did you make the appropriate changes between 3.0 and 3.1?
And did you ensure to update the module (and all others) also?

Avatar
ee

Community Member, 7 Posts

23 June 2015 at 9:06pm

Hi Pyromanik, this is all on a new fresh install of v3.1.

Go to Top