Flushing the cache

keevitaja - 3 months ago

Hi! Is there an easy way to flush the cache when admin updates/creates/deletes something in the admin section?

If not, then how do i flush the cache, when admin modifies file/post/page/navigation including the repeaters and custom fields?

Thanks a lot for the help!

mattcdavis1 - 3 months ago

Listening for the eloquent saved event should capture most updates although not all (i have a ticket open for this here: https://github.com/pyrocms/pyrocms/issues/4300)

As far as clearing the cache, that's just something like the below (i use this when deploying new code):

<?php namespace Union\AppModule\Http\Controller;

use Illuminate\Cache\CacheManager;

class UtilController extends PublicController
{
    protected $excludedMiddleware = [
        'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
    ];

    public function deploy(CacheManager $cache)
    {
        opcache_reset();

        $cache->flush();
    }
}

keevitaja - 3 months ago

yeah, that is one option

        \Event::listen('eloquent.saved: *', function($event) {
            cache()->flush();
        });

But it would be nicer to target a specific module(s).

@mattcdavis1 what happens to opcache_reset(); when opcache is not installed?