jean-beru/fos-http-cache-cloudfront
CloudFront proxy implementation for FOSHttpCache. Create an AWS CloudFront client, instantiate the proxy with your distribution ID, purge single URLs or wildcard patterns, then call flush(). Supports custom caller reference generators to avoid duplicate requests.
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).| Change | Type | Assessment Impact |
|---|---|---|
chore: … drop friendsofsymfony/http-cache 2.x (PR #13) |
Breaking | Raises the minimum supported FOSHttpCache to 3.x. Any app (or internal library) still resolving friendsofsymfony/http-cache:^2 must be upgraded before adopting 1.3.0. Pinning ^1.2 becomes the safe fallback only if 2.x support is a hard requirement. |
fix: pass CallerReference as string to createInvalidation (PR #11) |
Correctness fix | Previously the caller reference could be serialized as a non-string, producing CloudFront InvalidArgument 400s on invalidation. This directly retires our highest-likelihood runtime failure mode and makes the DateCallerReferenceGenerator dedup strategy trustworthy. |
fix: type url parameter of CloudFront::purge() (PR #15) |
Behavioural / minor BC | Method signature is now strictly typed. Callers passing ints, Stringable objects, or unvalidated route parameters will now hit a TypeError instead of an implicit cast. Audit call sites; cast explicitly. |
fix: README links and code samples (PR #12) |
Documentation | Reduced ramp-up friction. Note: README now shows the async-aws client — the PoC snippet in our prior assessment used the AWS SDK v2 Aws\CloudFront\CloudFrontClient, which conflicts. Corrected below. |
chore: update CI workflow and add Dependabot (PR #10) |
Supply chain / maintenance | Positive maintenance signal: automated dependency visibility and a maintained CI matrix. Slightly reduces the "small-maintainer" bus-factor risk, though it remains a single-maintainer package. |
Verdict: update required. The 2.x dependency drop is a breaking change for a subset of adopters, and the CallerReference fix changes the risk posture.
/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 / friendsofsymfony/http-cache ^3.0 (2.x no longer accepted as of 1.3.0).aws/aws-sdk-php (if using v2; avoid due to conflicts).cache facade (for hybrid caching strategies).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| FOSHttpCache 2.x → 3.x Upgrade (new, 1.3.0) | High | Inventory transitive friendsofsymfony/http-cache constraints (composer why). Upgrade to 3.x in the same change window; validate Symfony component versions and PHP floor. Pin ^1.3 only after resolution succeeds. |
| 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. |
Strict purge() Parameter Typing (new, 1.3.0) |
Medium | Grep invalidation call sites for non-string arguments (ints, Stringable, route models); cast explicitly and add a static-analysis rule (PHPStan level ≥ 5). |
| 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 (downgraded) | 1.3.0 fixes CallerReference string casting; DateCallerReferenceGenerator deduplication now behaves as documented. Retain a dedup assertion in tests. |
| Single-Maintainer / Bus Factor | Medium (slightly improved) | Dependabot + CI added; still a one-maintainer package. Track upstream releases; budget for a fork if abandoned. |
friendsofsymfony/http-cache:^2, and what blocks a 3.x upgrade (Symfony minor version, PHP floor, custom proxy subclasses)?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 3.x | ✅ Direct extension (assumes existing FOSHttpCache setup). |
| FOSHttpCache 2.x | ❌ Dropped in 1.3.0 — stay on ^1.2 or upgrade. |
| 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). |
composer why friendsofsymfony/http-cache across all affected services.^1.2 and defer.DefaultCacheBehavior (ForwardedValues, TTL) and Origin (S3, ALB, or custom origin).composer require jean-beru/fos-http-cache-cloudfront:^1.3 async-aws/cloudfront
// config/cloudfront.php
'distribution_id' => env('CLOUDFRONT_DISTRIBUTION_ID'),
'region' => env('AWS_REGION'),
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('cloudfront.proxy', function ($app) {
return new \JeanBeru\HttpCacheCloudFront\Proxy\CloudFront(
new \AsyncAws\CloudFront\CloudFrontClient([
'region' => $app['config']['cloudfront.region'],
]),
['distribution_id' => $app['config']['cloudfront.distribution_id']]
);
});
}
$proxy = app('cloudfront.proxy');
$proxy->purge('/homepage')->purge('/assets/*')->flush();
Cache facade to delegate invalidations and register via Facade::extend().php artisan cache:purge /path/to/invalidate.eloquent.updated), dispatching to a queue job to keep request latency flat.^1.3 and lockfile-pin async-aws/cloudfront. Upstream is pre-2.0, so treat minor bumps as potentially breaking and read changelogs — 1.3.0 itself demonstrates this (a "chore" PR dropped a major dependency).app/ rather than forking the package, so a future replacement is a one-file change.Invalidation.Id, and API errors, and emits a metric per purge.createInvalidation errors (auth, throttling, malformed path, InvalidArgument). 1.3.0 removes the caller-reference class of failures; the rest remain caller-handled.flush().| Mode | Symptom | Containment |
|---|---|---|
| CloudFront API error / throttle | Stale content at edge | Retry with backoff; log; alert on error rate |
| Missing/misconfigured IAM | All purges fail fast | Pre-flight check in deploy; synthetic purge in smoke tests |
| Wildcard purge over-reach | Cache churn, cost spike, origin load | Restrict patterns; monitor invalidation path counts |
| Origin cannot absorb post-purge load | Latency spike / 5xx on cold cache | Rate-limit purges; stagger; verify origin autoscaling |
Dependency drift (composer update) |
Runtime TypeError / class-not-found |
Lockfile pinning, CI composer validation, staging gate |
Cache-Control/s-maxage, FOSHttpCache proxy semantics, and CloudFront invalidation quotas.How can I help you explore Laravel packages today?