Increasing partial cache lifetime


#1

In SS4, the previously documented way of changing the partial cache lifetime no longer works

SS_Cache::set_cache_lifetime('cacheblock', 60 * 60 * 24 * 7);

Does anyone have any clue how to increase the lifetime now?


#2

Try:

SilverStripe\Core\Injector\Injector:
  Psr\SimpleCache\CacheInterface.cacheblock:
    constructor:
      defaultLifetime: 604800 # 7 days

From https://docs.silverstripe.org/en/4/developer_guides/performance/caching/#invalidation


#5

I tried that and it does not work for me. :frowning: The lifetime is still 10 minutes. Does it require any other configuration? I just created the new file cache.yml and copied your code.

EDIT: Ok, it looks like it doesn´t work only on localhost, it seems to work fine on production server.


#3

Hi JonoM,
Thank you for your suggestion.
I have tried that before and it didn’t have any effect on the partial cache lifetime (still refreshes after 10min)
I am currently accessing the cache via:

<% cached 'sidenav', $List('SilverStripe\CMS\Model\SiteTree').max('LastEdited'), $List('SilverStripe\CMS\Model\SiteTree').count() %>
    <% loop $Menu(1) %>
        ...
    <% end_loop %>
<% end_cached %>

#4

The correct answer is to create a new config file in the app/_config directory. I called mine cache.yml. Then you need to specify a priority so that it doesn’t get stomped on by the SilverStripe config that it is meant to override in the first place e.g the “After” priority in the config header:


 ---
 Name: appcache
 After: '*#corecache'
 ---
 SilverStripe\Core\Injector\Injector:
   Psr\SimpleCache\CacheInterface.cacheblock:
     constructor:
       defaultLifetime: 604800