Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

myregistration's avatar

How do you bust Sushi cache programmatically?

I want to bust the sushi cache using a function call, but I don't see a way to do that. I want to call a method to clear sushi cache after I update relative records, but store them in cache otherwise so loads quickly.

0 likes
2 replies
LaryAI's avatar

Certainly! Sushi caches the data in a file, and by default, it stores the cache in the storage/sushi directory. To "bust" or clear the Sushi cache programmatically, you can delete the cache file associated with your model.

Assuming your model uses Sushi like this:

use Sushi\Sushi;

class MyModel extends Model
{
    use Sushi;
}

You can clear the cache by deleting the cached file. Here’s a function you can add to your model or a helper class to bust the Sushi cache:

use Illuminate\Support\Facades\File;

public static function bustSushiCache()
{
    $model = new static;
    $cachePath = storage_path('sushi/' . $model->getSushiCacheFilename());

    if (File::exists($cachePath)) {
        File::delete($cachePath);
    }
}

Usage:

MyModel::bustSushiCache();

Note:

  • getSushiCacheFilename() is a protected method in the Sushi trait, so you may need to add a public wrapper in your model if you want to access it directly.
  • If you want to bust cache for multiple Sushi models, call this method on each model.

Alternative:
If you want to clear all Sushi caches:

File::cleanDirectory(storage_path('sushi'));

Summary:
Call your custom bustSushiCache() method after updating the underlying data to ensure Sushi reloads the data on the next request.

myregistration's avatar

I was able to create the following method, but seems like there should be flush() method available for any sushi instance. I use it in both mount() and after update table data.

public static function flush()
{
    $instance = (new static);

    $cachePath = $instance->sushiCachePath();
    $dataPath = $instance->sushiCacheReferencePath();

    $instance->cacheFileNotFoundOrStale($cachePath, $dataPath, $instance);
}

I'm using cacheFileNotFoundOrStale instead of delete because there was an error with sqlite not being found otherwise. Is sushi's migrate() meant for flushing?

Please or to participate in this conversation.