SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

Automatically ?flush when in 'dev' mode

Often when doing development work on a website - and particularly the templates - it can be a pain having to remember to add ?flush to the end of the URL to make sure all of your changes have come through. I'm sure that all of us have had that "d'oh" moment when we have spent too much time wondering why our changes weren't working, only to find a simple flush fixed it.

If you have set up a domain in your set_dev_servers array or added Director::set_environment_type('dev') to your _config.php file then you can also add:

if (Director::isDev()) {
SSViewer::flush_template_cache();
}

This will flush the template cache on every page load.

NB: This will not regenerate cached images, if you want to do that you will have to add $_GET['flush'] = 1; inside the above conditional statement.

Daniel Hensby avatar

Daniel Hensby

Dan runs a website development company called Better Brief. Better Brief specialise in SilverStripe websites and takes an active role in the UK SilverStripe community, attending SS Meetups and even presenting at them.

  • alex
    15/11/2010 8:39pm (4 years ago)

    Is this how it should look adding the conditional statement?

    if (Director::isDev()) {
    SSViewer::flush_template_cache(); $_GET['flush'] = 1;
    }

    Sorry pretty new to all this, thanks - alex

  • Daniel Hensby
    15/11/2010 9:15pm (4 years ago)

    Yep, looks good!

  • swaiba
    07/01/2011 2:50pm (4 years ago)

    I just posted on the _config.php cheatsheet because this fragment caused the site to continuously error in dev mode so I had to remove it

  • aleks
    23/02/2011 12:32am (4 years ago)

    Many thanks for this!

    Saved my over-annoyance meter from exploding right now.

Post a comment ...

You cannot post comments until you have logged in. Login Here.

Advertisement

Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image Daniel Hensby
3 article image Marcus Dalgren
4 article image Hamish Campbell
5 article image Ty Barho
6 article image Martijn van Nieuwenhoven
7 article image Darren-Lee
8 article image Roman Schmid
9 article image Matt Clegg
10 article image dalesaurus

View full leaderboard


Advertisement