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.