PHP code example of acpl / flarum-lscache

1. Go to this page and download the library: Download acpl/flarum-lscache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acpl / flarum-lscache example snippets


(new Extend\Routes('api'))
    ->get('/examples', 'examples.index', ExamplesListController::class)
    ->get('/examples/{id}', 'examples.show', ExamplesShowController::class)
    ->post('/examples', 'examples.create', ExamplesCreateController::class);

// extend.php
use Acpl\FlarumLSCache\Utility\LSCachePurger;
use Flarum\Extend;

return [
    // ... your current extenders
    (new Extend\Conditional)
        ->whenExtensionEnabled('acpl-lscache', function () {
            LSCachePurger::$resourcesSupportedByEvent[] = 'example';

            return [
                (new Extend\Event)->listen(ExampleUpdated::class, ExampleUpdatedListener::class),
            ];
        }),
];

// ExampleUpdatedListener.php
use Acpl\FlarumLSCache\Listener\AbstractCachePurgeListener;

/** @extends AbstractCachePurgeListener<ExampleUpdated> */
class ExampleUpdatedListener extends AbstractCachePurgeListener
{
    protected function addPurgeData(object $event): void
    {
        $this->purger->addPurgeTags([
            'examples',
            "example_{$event->example->id}",
        ]);
    }
}

// extend.php
use Acpl\FlarumLSCache\Utility\LSCachePurger;
use Flarum\Extend;

return [
    // ... your current extenders
    (new Extend\Conditional)
        ->whenExtensionEnabled('acpl-lscache', function () {
            LSCachePurger::$resourcesSupportedByEvent[] = 'example';

            return [
                (new Extend\Event)->subscribe(ExampleEventSubscriber::class),
            ];
        }),
];

// ExampleEventSubscriber.php
use Acpl\FlarumLSCache\Listener\AbstractCachePurgeSubscriber;
use Illuminate\Contracts\Events\Dispatcher;

class ExampleEventSubscriber extends AbstractCachePurgeSubscriber
{
    public function subscribe(Dispatcher $events): void
    {
        $this->addPurgeListener($events, ExampleUpdated::class, $this->handleExampleUpdated(...));
        // ... rest of listeners
    }

    public function handleExampleUpdated(ExampleUpdated $event): void
    {
        $this->purger->addPurgeTags([
            'examples',
            "example_{$event->example->id}",
        ]);
    }
    // ... rest of methods
}
sh
composer update acpl/flarum-lscache
php flarum migrate
php flarum cache:clear
sh
php flarum lscache:clear
php flarum lscache:clear --path=/tags --path=/d/1-test