Janitor flush specific page

Hi @bnomei,

I would like to delete only one specific page (the home for example) using your janitor:flush built it command, but I don’t get what should I pass to the --name parameter to do so.

I tried the following command, but it doesn’t work:

janitor()->command('janitor:flush --name home --quiet');

I’m not sure it makes any difference, but I’m using staticache plugin and it’s a multilingual K3 website, so the cache files I’m trying to delete are:

  • /pages/fr/index.html
  • /pages/de/index.html
  • /pages/en/index.html

Thanks for your help :pray:

neither kirby core not janitor support flushing a single page within the core pages cache. the name parameter should be set on the id of a cache like “pages” or “my.plugin”.

but you could create a custom command that removes the files you need given a page id. and then call that from janitor.

on second thought… since the core pages cache (even if its powered by staticache plugin like in your case) adheres to the cache class interface your command could do something like this (untested).

REMOVED

and iterate over each language. i might find the time early next week to add that to janitor. I will report back then.

edited: removed the untested code example as it did not work as intended.

1 Like

v4.4.0 adds the trash command which you can use in the CLI and as a panel button to remove entries of any cache by key. by default it will remove the pages cache for the current page.

  janitor_trash:
    type: janitor
    command: 'janitor:trash'
    label: Removes Pages Cache for this page
    icon: trash
1 Like

Thank you very much for the new trash command! :pray:
I tried to use it as follow, but it doesn’t work:

janitor()->command('janitor:trash --key home --quiet')

Did you test it for multilang websites with staticache plugin?
I am triggering it via the following webhook:

'routes' => [ 
  [
      'pattern' => 'webhook/(:any)/(:any)',
      'action' => function($secret, $command) {
        if ($secret != janitor()->option('secret')) {
          \Kirby\Http\Header::status(401);
          die();
        }
        if ($command === 'janitor-trash-home') {
          janitor()->command('janitor:trash --key home --quiet');
        }
      }
    ]
]

The pages cache creates a key for each language. Something like home.en.html. it will be the same key with or without the staticache plugin. But using the --page argument will be easier.

web hook PHP

janitor()->command('janitor:trash --page home');

since Janitor v4.3 the --quiet will automatically be appended if running commands in PHP and not the CLI

CLI
kirby janitor:trash --page home

some more examples on how to use the arguments directly in the command itself

1 Like

Thanks, it works perfectly now! :tada:

The examples you added as comments in the command itself are very useful!
I even think you should add them directly to the plugin README, at least for those with arguments, to make them more accessible.