jean-beru/fos-http-cache-cloudfront
CloudFront proxy implementation for FOSHttpCache. Create a CloudFrontClient, configure your distribution ID, then purge/invalidate specific URLs or patterns (e.g., /assets/*) and flush requests. Supports caller reference generators to avoid duplicate invalidations.
purge(), flush()) with CloudFront-specific logic, reducing boilerplate for AWS API calls.async-aws/cloudfront to handle low-level CloudFront API interactions (e.g., invalidations, warmup)./homepage) and wildcard (/assets/*) purges.purge() (CloudFront pre-loads URLs on invalidation).Cache-Control settings (configured separately).cache() facade or Cache tagging.async-aws/cloudfront (AWS SDK v3).symfony/http-cache (for FOSHttpCache compatibility).aws/aws-sdk-php (if using v2; avoid due to conflicts).cache facade (for hybrid caching strategies).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| AWS SDK Version Conflicts | High | Enforce async-aws/cloudfront via composer.json and resolve with platform-check. |
| Laravel Integration Gaps | High | Create a custom service provider to bind the proxy and extend Laravel’s Cache facade. |
| CloudFront Configuration Drift | Medium | Validate CacheBehaviors (e.g., ForwardedValues, TrustedSigners) before adoption. |
| Rate Limiting | Medium | Monitor CloudFront API throttling (default: 1,000 requests/second); batch purges. |
| Testing Complexity | Medium | Use mocks for AWS SDK in unit tests; integrate with Laravel’s HTTP tests for E2E. |
| Duplicate Invalidations | Low | Use DateCallerReferenceGenerator to deduplicate requests within a time window. |
cloudfront:CreateInvalidation) granted to the Laravel app’s IAM role?file/redis cache drivers or act as a secondary cache layer?Cache-Control headers be synchronized between Laravel and CloudFront?eloquent.updated) or custom commands?| Component | Compatibility |
|---|---|
| Laravel 9+/PHP 8.1+ | ✅ Full support (Symfony HTTP Cache components). |
| AWS CloudFront | ✅ Required (package is CloudFront-specific). |
| FOSHttpCache | ✅ Direct extension (assumes existing FOSHttpCache setup). |
| Redis/Memcached | ⚠️ Partial (can complement but not replace). |
| Guzzle/AWS SDK v2 | ❌ Conflicts (use async-aws/cloudfront instead). |
| Laravel Queues | ❌ No native support (requires custom integration). |
Phase 1: Assessment (1-2 weeks)
DefaultCacheBehavior (e.g., ForwardedValues, TTL).Origin (e.g., S3, ALB, or custom origin).Phase 2: PoC (1 week)
composer require jean-beru/fos-http-cache-cloudfront async-aws/cloudfront
// config/cloudfront.php
'distribution_id' => env('CLOUDFRONT_DISTRIBUTION_ID'),
'region' => env('AWS_REGION'),
// app/Providers/AppServiceProvider.php
public function boot()
{
$this->app->singleton('cloudfront.proxy', function ($app) {
return new \JeanBeru\HttpCacheCloudFront\Proxy\CloudFront(
new \Aws\CloudFront\CloudFrontClient($app['config']['cloudfront']),
['distribution_id' => $app['config']['cloudfront.distribution_id']]
);
});
}
$proxy = app('cloudfront.proxy');
$proxy->purge('/homepage')->purge('/assets/*')->flush();
Phase 3: Laravel Integration (1-2 weeks)
Cache facade to delegate invalidations:
// app/Extensions/CacheExtension.php
public function cloudfrontPurge($path)
{
return app('cloudfront.proxy')->purge($path);
}
Register via Facade::extend().php artisan cache:purge /path/to/invalidate
// app/Listeners/PurgeCacheOnUpdate.php
public function handle($event)
{
app('cloudfront.proxy
How can I help you explore Laravel packages today?