Download the PHP package methorz/http-cache-middleware without Composer

On this page you can find all versions of the php package methorz/http-cache-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-cache-middleware

MethorZ HTTP Cache Middleware

PSR-15 HTTP caching middleware with ETag support and RFC 7234 compliance

CI codecov PHPStan PHP Version

Automatic HTTP caching for PSR-15 applications with ETag generation, 304 Not Modified responses, and Cache-Control header management. Zero configuration, production-ready.


โœจ Features


๐Ÿ“ฆ Installation


๐Ÿš€ Quick Start

Basic Usage

That's it! All GET and HEAD requests will now have:


๐Ÿ“– Detailed Usage

With Cache-Control Directives

Generated Headers:

Configuration Options

Development Mode (Disable Caching)

For development, you want fresh data on every request. Simply disable the middleware:

Recommended approach: Only add CacheMiddleware to your production pipeline configuration, not in development.


๐ŸŽฏ Cache-Control Directive Builder

Fluent interface for building Cache-Control headers:

Common Patterns

Public, cacheable for 1 hour:

Private, no caching:

Immutable assets (images, CSS, JS):

API responses with shared cache:

All Directives

Method Description Example
public() Cache may be stored by any cache public
private() Cache only for single user private
noCache() Must revalidate before use no-cache
noStore() Must not be stored anywhere no-store
maxAge(int) Maximum freshness time max-age=3600
sMaxAge(int) Shared cache max age s-maxage=7200
mustRevalidate() Must revalidate when stale must-revalidate
proxyRevalidate() Proxy must revalidate proxy-revalidate
noTransform() Cache must not transform response no-transform
staleWhileRevalidate(int) Serve stale while fetching fresh stale-while-revalidate=60
staleIfError(int) Serve stale if origin errors stale-if-error=120
immutable() Response will never change immutable

๐Ÿท๏ธ ETag Generation

Automatic ETag Generation

ETag Utilities


๐Ÿ”„ How It Works

1. First Request (Cache Miss)

Client caches response with ETag

2. Subsequent Request (Cache Validation)

Benefits:


๐ŸŽฏ Use Cases

1. Static Asset Caching

2. API Response Caching

3. Dynamic Content with Validation

4. Private User Data

5. CDN Integration


๐Ÿ”ง Configuration Examples

Mezzio / Laminas

Per-Route Configuration


๐Ÿ“Š HTTP Headers Reference

Request Headers (Client โ†’ Server)

Header Description Example
If-None-Match Conditional request with ETag "abc123" or W/"abc123" or *
If-Modified-Since Conditional request with date Wed, 21 Oct 2015 07:28:00 GMT

Response Headers (Server โ†’ Client)

Header Description Example
ETag Entity tag for resource version "abc123" or W/"abc123"
Cache-Control Caching directives public, max-age=3600
Expires Absolute expiration time Wed, 21 Oct 2025 07:28:00 GMT
Last-Modified Resource modification time Wed, 21 Oct 2024 07:28:00 GMT

๐Ÿงช Testing

Test Coverage: 37 tests, 57 assertions, 100% passing


โšก Performance Impact

Bandwidth Savings

Server Load Reduction


๐Ÿ”’ Security Considerations

Private vs Public

Cache Invalidation

This middleware handles validation (304 responses), not invalidation. For cache invalidation:


๐Ÿ“š Resources


๐Ÿ”— Related Packages

This package is part of the MethorZ HTTP middleware ecosystem:

Package Description
methorz/http-dto Automatic HTTP โ†” DTO conversion with validation
methorz/http-problem-details RFC 7807 error handling middleware
methorz/http-cache-middleware HTTP caching with ETag support (this package)
methorz/http-request-logger Structured logging with request tracking
methorz/openapi-generator Automatic OpenAPI spec generation

These packages work together seamlessly in PSR-15 applications.


๐Ÿ“„ License

MIT License. See LICENSE for details.


๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.


๐Ÿ”— Links


All versions of http-cache-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package methorz/http-cache-middleware contains the following files

Loading the files please wait ...