When migrating a Craft site, I'm used to...

  1. deploying files
  2. checking my config, tweaking as necessary
  3. loading a database backup
  4. running "Update Asset Indexes" and "Clear Caches" from the control panel

That last step is always important because random oddities and broken images are fixed site-wide because of caching and transforms. Now I'm attempting to automate the process with a Docker deploy script, so I'm wondering: is there any way to Update Asset Indexes and Clear Caches programmatically?

I know that you can nuke the craft_assettransformindex table and delete the contents of /craft/storage/runtime/assets and /craft/storage/runtime/cache (related question), but is that really doing the exact same thing?

Note that by "programmatically," I generally mean anything you could achieve from a Linux terminal: MySQL commands, PHP or shell scripts, etc.

  • Which caches, specifically, do you want to clear? The clear caches tool has options for the various different places caching is occurring in Craft.
    – Brad Bell
    Commented Sep 23, 2014 at 20:47
  • @BradBell Amended answer: ideally all caches, but realistically only those that'd be kept in MySQL since the filesystem would be squeaky clean on deploy—no physical transforms present and no additions to /craft/storage/runtime/assets.
    – Matt Stein
    Commented Sep 23, 2014 at 20:48
  • I'm going with Fred's answer, then. :)
    – Brad Bell
    Commented Sep 23, 2014 at 20:58

2 Answers 2


I guess it depends. So, behind the scenes, Craft can have different cache drivers. You might use the db or file cache, or something like Redis or Memcache.

Took a peek at ClearCachesTool, and it looks like it's doing the things you mentioned:


As well as deleting all the internal cache folders (runtime/cache, assets, compiled_templates, temp), including any plugin cache paths that have registered via registerCachePaths.


It also deletes the templates cache.

I guess what you're looking for are these:

  • CacheService->flush()
  • ClearCachesTool->performAction() (does most of the clearing)
  • craft()->templateCache->deleteAllCaches(); (called in ClearCachesTool - TemplateCacheService)

So yes, you can either bootstrap Craft and call a php file from the commandline, or add a plugin with an action that you GET/POST to after deployment.

The former, you can do with the included bootstrap.php file (as of 2.2)

$craft = require 'craft/app/bootstrap.php';
  • Perfect, thank you for the great answer Fred!
    – Matt Stein
    Commented Sep 23, 2014 at 21:01


Craft version 3+ now has console commands built in that can handle these tasks.

$ php craft clear-caches/all
$ php craft index-assets/all

See documentation for Console Commands in 3.x or Console Commands in 4.x

Craft v2

Take a look at Craft CLI. It's a command line interface for Craft.

It let's you run commands like craft clear:cache and craft update:assetsindexes from the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.