Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Http Cache Bundle Laravel Package

friendsofsymfony/http-cache-bundle

Symfony bundle to enhance HTTP caching: configure cache headers by path/controller, tag responses and invalidate by tags, set up invalidation schemes without code, send purge/ban requests efficiently, vary cache by user type, and plug in custom cache clients.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Symfony Native Integration: Continues to leverage Symfony’s dependency injection, event system, and configuration paradigms, ensuring seamless ecosystem alignment (e.g., attributes, PSR-17 HTTP factories).
    • Granular Control: Retains support for path-based, role-based, and tag-based caching rules, enabling fine-grained cache management without monolithic configurations.
    • Extensibility: Custom HTTP cache clients (e.g., Varnish, Nginx, Cloudflare, Fastly, AWS CloudFront) remain supported via plugins or interfaces, reducing vendor lock-in.
    • Invalidation Flexibility: Passive (header-based) and active (purge API) invalidation strategies are preserved, critical for dynamic content (e.g., user-specific or time-sensitive data).
    • Modern PHP/Symfony Support: Actively maintained for PHP 8.1+ and Symfony 6/7/8, with deprecation handling for older versions.
  • Cons:

    • Symfony Dependency: Tight coupling to Symfony’s kernel, event system, and configuration (e.g., YAML/attributes) persists. Non-Symfony PHP projects would still require significant abstraction.
    • Complexity for Simple Use Cases: Overhead remains for projects with minimal caching needs (e.g., static sites or read-heavy APIs without invalidation).
    • Varnish-Centric Design: While supporting other proxies, core features (e.g., tag-based invalidation) are most robust with Varnish. Nginx/Symfony HttpCache support remains partial.

Integration Feasibility

  • Symfony Projects: High feasibility—drop-in installation via Composer, minimal boilerplate (e.g., fos_http_cache config in config/packages/). Attributes-based configuration (Symfony 5+) reduces XML/YAML verbosity.
    • Example integration path:
      1. Install via Composer: composer require friendsofsymfony/http-cache-bundle.
      2. Configure fos_http_cache.yaml for rules (e.g., CacheRule for /api/* with max_age: 3600).
      3. Add [Cache(ttl: 3600)] attributes to controllers/actions.
      4. Set up a proxy client (e.g., Varnish) in proxy_client config.
  • Non-Symfony PHP: Low feasibility—would require rewriting event listeners, dependency injection, and configuration logic.
  • Microservices/APIs: Moderate feasibility—works well for REST APIs with cacheable endpoints, but invalidation logic (e.g., tagging) may need customization for event-driven architectures.

Technical Risk

  • Breaking Changes: No breaking changes introduced in 3.4.1. However, prior major versions (3.x) dropped Symfony 5.x support and deprecated annotations in favor of attributes. Migration from 2.x still requires:
    • Configuration structure updates (e.g., generate_url_type flexibility).
    • Attribute-based annotations (e.g., @Cache[Cache]).
    • Proxy client initialization adjustments (e.g., lazy-loading for Cloudflare/Fastly).
  • Proxy-Specific Quirks:
    • Varnish: Fully supported; tag-based invalidation works out-of-the-box.
    • Nginx/Symfony HttpCache: Limited tag support; may require custom PurgeTagsListener configuration.
    • Cloudflare/Fastly: Requires additional packages (jean-beru/fos-http-cache-cloudfront) and runtime secrets (e.g., API tokens).
  • Performance Overhead:
    • Invalidation requests add latency (~50–200ms RTT for HTTP purges). Mitigate by:
      • Using async invalidation (e.g., Symfony Messenger).
      • Batch invalidations for bulk operations (e.g., admin actions).
    • Cache header generation adds minimal overhead (~1–5ms per request).
  • Edge Cases:
    • Flash Messages: Redirects with fos_http_cache may lose flash messages if not configured (fixed in 2.10.2+).
    • Session Handling: Context invalidation (e.g., logout) requires ContextInvalidationSessionLogoutHandler.
    • PSR-17 Factories: Custom request_factory/stream_factory needed for non-standard HTTP clients.

Key Questions for TPM

  1. Proxy Strategy:
    • Which HTTP cache proxy is in use (Varnish/Nginx/Cloudflare)? Does it support tag-based invalidation?
    • Are there multi-region deployments requiring geo-specific cache invalidation?
  2. Invalidation Granularity:
    • Is tag-based invalidation needed (e.g., for user-specific or product catalog data), or is path-based sufficient?
    • How frequently are caches invalidated? (High invalidation rates may require async queues.)
  3. Symfony Version:
    • Is the project on Symfony 6/7/8? If not, is migration to 3.x of the bundle feasible?
  4. Customization Needs:
    • Are there non-standard cache headers (e.g., Surrogate-Key) or proxy-specific extensions?
    • Is there a need to integrate with third-party cache services (e.g., Redis as a backend for tag storage)?
  5. Monitoring:
    • How will cache hit/miss ratios and invalidation success rates be monitored?
    • Are there SLIs/SLOs for cache performance (e.g., <100ms purge latency)?
  6. Fallback Mechanisms:
    • What’s the plan for cache failures (e.g., proxy downtime)? Bypass caching or degrade gracefully?
  7. Testing:
    • Are there existing tests for cache behavior? How will invalidation logic be verified in CI?
  8. Team Expertise:
    • Does the team have experience with Symfony’s event system and attributes? If not, is training needed?

Integration Approach

Stack Fit

  • Symfony Ecosystem: Optimal fit—designed for Symfony’s architecture (events, DI, attributes). Complements:
    • Symfony HttpClient: For proxy client implementations.
    • Symfony Messenger: For async invalidation (e.g., via fos:httpcache:clear command).
    • Doctrine: Tag-based invalidation can sync with Doctrine events (e.g., postPersist).
    • API Platform: Works with @ApiResource caching strategies.
  • Non-Symfony PHP: Poor fit—would require significant refactoring to decouple from Symfony’s kernel/events.
  • Other Frameworks:
    • Laravel: Could adapt core logic (e.g., middleware for headers, queue jobs for invalidation), but lacks Symfony’s attribute/config system.
    • Node.js/Python: No direct portability; would need to reimplement cache header logic and proxy APIs.

Migration Path

Current State Migration Steps Risks
No HTTP Caching 1. Install bundle. 2. Configure fos_http_cache.yaml with basic CacheRules. 3. Add [Cache] attributes to controllers. 4. Deploy proxy (e.g., Varnish). Minimal; focus on proxy setup and header validation.
Symfony HttpCache 1. Replace HttpCache with FOSHttpCacheBundle for tag support. 2. Migrate from HttpCacheStore to fos_http_cache config. 3. Update invalidation logic to use PurgeTagsListener. Tag-based invalidation may require proxy-specific tweaks.
Varnish/Nginx Cache 1. Update VCL/Nginx config to honor Surrogate-Control headers. 2. Configure proxy_client in bundle. 3. Test tag invalidation (e.g., curl -X PURGE http://proxy/tags:user_123). Nginx may need custom PurgeTagsListener for tag support.
Custom Cache Headers 1. Extend FOSHttpCacheBundle via custom CacheRule or ResponseMatcher. 2. Use match_response config for complex logic. 3. Validate headers with tools like curl -I. Complex logic may require custom event listeners.
Legacy Annotations (Symfony <5) 1. Replace @Cache annotations with [Cache] attributes. 2. Update fos_http_cache.yaml to remove annotations section. 3. Test all cached routes. Attribute migration may miss some routes if not thoroughly tested.

Compatibility

  • Symfony Versions:
    • Supported: 6.4+, 7.x, 8.x (as of 3.x bundle).
    • Legacy: 5.x (use 2.x bundle) or 4.x (use 2.11.x).
  • PHP Versions:
    • Required: 8.1+ (3.x bundle).
    • Legacy: 7.4+ (2.x bundle).
  • Proxy Clients:
    • Fully Supported: Varnish, Symfony HttpCache.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
escalated-dev/escalated-laravel
escalated-dev/locale
vusys/laravel-runabout
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php