To manually flush the in-memory cache in Laravel Pennant, you can use the `flushCache` method provided by the `Feature` facade. This method clears the cached feature flag results stored in memory during a single request, ensuring that subsequent feature checks will re-resolve the feature values rather than using the cached ones.
Here is how you do it in code:
php
use Laravel\Pennant\Feature;
Feature::flushCache();
This will clear the in-memory cache of all resolved features for the current request lifecycle. It is particularly useful if you have updated feature flags during a request and want to ensure the new values are used immediately without waiting for the next request cycle[6].
This manual cache flush applies specifically to Pennant's internal in-memory cache and does not affect any external cache or storage backend you might be using (such as a database or Redis). If you want to clear cached data stored in other layers, you would need to handle those separately.
In summary, to manually flush Pennantâs in-memory cache, simply call:
php
Feature::flushCache();
This resets the cached feature flag results for the current request[6].
Citations:
[1] https://www.laars.com/images/uploads/products/1204E-NH.pdf
[2] https://www.laars.com/images/uploads/products/1176J-NH.pdf
[3] https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/16_Waking_and_Sleeping/flushing-caches.html
[4] https://www.felixcloutier.com/x86/clflush
[5] https://www.kernel.org/doc/html/v5.0/core-api/cachetlb.html
[6] https://laravel.com/docs/12.x/pennant
[7] https://articles.peterfox.me/laravel-feature-flags-choosing-a-package-974c33fbb91a
[8] https://laravel.com/docs/11.x/cache
[9] https://stackoverflow.com/questions/51818655/clflush-to-invalidate-cache-line-via-c-function
[10] https://wpwebinfotech.com/blog/laravel-pennant-guide/
[11] https://www.honeybadger.io/blog/a-guide-to-feature-flags-in-laravel/
[12] https://stackoverflow.com/questions/77078816/how-to-disable-caching-for-laravel-pennant-in-db