- How do I install nexxai/laravel-cfcache in a Laravel application?
- Install it with Composer using composer require nexxai/laravel-cfcache. Laravel package auto-discovery registers the service provider, so you do not need to add anything manually to config/app.php on modern Laravel versions. Publish the package config next and set your Cloudflare API token and zone ID before running any purge commands.
- Does laravel-cfcache purge Cloudflare cache automatically when an Eloquent model changes?
- Automatic model-driven purging is the core use case: you define rules that map model changes to the URLs or tags to purge, usually wired up in a model observer or an event listener. The package then performs the Cloudflare API call when a rule fires. Because the trigger lives in your application code, you decide exactly which models and events cause a purge, and you should queue that work instead of running it inside the request.
- Which Cloudflare purge operations does laravel-cfcache support?
- The package targets Cloudflare's cache purge API and covers purge by URL, purge by cache tag, and purge everything, exposed primarily through Artisan commands. The exact programmatic surface added in v1.6.0 is not fully documented, so check the facade or service contract in the source before depending on tag or host-level purges from application code. For bulk changes, confirm whether the package batches URLs into a single API call or issues one HTTP request per item.
- Can I trigger a Cloudflare purge from a job or service class instead of Artisan::call?
- Yes. v1.6.0 adds a programmatic entry point so purges can be triggered from services, event listeners, model observers, and queued jobs rather than shelling out through Artisan. That is the recommended pattern, because cache invalidation is an event-driven concern and calling the console layer from business logic couples code to CLI availability and makes testing awkward. Verify the returned contract in the exact version you install, since the release note describes the capability loosely.
- Is it safe to call laravel-cfcache from inside a web request?
- Programmatic purges most likely perform a blocking HTTP call to the Cloudflare API in the caller's execution context, which adds latency and a new failure path to user-facing requests. Wrap purges in a queued job with explicit HTTP timeout and retry settings so a slow or failing Cloudflare API never degrades your response times. Keep the Artisan commands available for manual and ops use.
- What happens when a Cloudflare purge fails: does the package throw an exception?
- Error semantics are not clearly documented, so it is unconfirmed whether failures throw, return a result object, or silently no-op. Silent failure is the dangerous case for a cache invalidation tool, because stale content keeps being served with no signal. Add logging and metrics in your own wrapper and assert on the real return value in a test against a faked HTTP client before relying on it in production.
- How do I test Cloudflare cache purging without hitting the real API?
- Use Laravel's HTTP client faking, Http::fake(), to stub Cloudflare's API responses and assert that your observer, listener, or job dispatches a purge with the expected URLs and tags. Keep the purge behind a thin application-owned service such as App\Services\CdnPurgeService so tests can swap in a fake implementation. Add a test that simulates a Cloudflare error to confirm your application logs or surfaces the failure rather than swallowing it.
- Which Laravel and PHP versions does laravel-cfcache support?
- The package targets modern Laravel applications, but the composer.json constraint and the CI matrix are the authoritative source, so check them before upgrading. The support matrix is currently unverified, so pin to ^1.6.0 and run your test suite to confirm existing scheduled commands behave identically. If you run an older Laravel or PHP version, verify compatibility in a branch before committing to the upgrade.
- Does laravel-cfcache support multiple Cloudflare zones and scoped API tokens?
- Credentials come from the publishable config file, an API token plus a zone ID, so a single-zone setup is the documented path. Multi-zone configuration is not clearly documented, so if you serve several domains behind Cloudflare, test whether zone can be overridden per call or whether you need separate configuration entries. Always use a scoped API token limited to cache purge permissions rather than a legacy global API key.
- Is laravel-cfcache actively maintained, and what should I do if it is not?
- It is a single-maintainer package with no published SLA, which is the main supply-chain risk alongside the undocumented programmatic contract. The surface is thin, a handful of cache helpers plus Artisan commands, so it is easy to hide behind your own CdnPurgeService and swap in direct Cloudflare API calls or another package if maintenance stalls. Pin the version, watch releases, and keep your own tests around the wrapper so a swap stays cheap.