Download the PHP package micheh/psr7-cache without Composer

On this page you can find all versions of the php package micheh/psr7-cache. 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 psr7-cache

Cache helpers for PSR-7 HTTP Messages

Build Status Code Coverage Scrutinizer Code Quality

This library provides an easy way to either add cache relevant headers to a PSR-7 HTTP message implementation, or to extract cache and conditional request information from a PSR-7 message (e.g. if a response is cacheable). It also provides a Cache-Control value object to provide an object oriented interface for the manipulation of the Cache-Control header.

Installation

Install this library using Composer:

Quickstart

To enable caching of HTTP responses, create an instance of CacheUtil, call the method withCache and provide your PSR-7 response.

This will add the header Cache-Control: private, max-age=600 to your response. With this header the response will only be cached by the client who sent the request and will be cached for 600 seconds (10 min). During this time the client should use the response from the cache and should not make a new request to the application.

Cache Validators

The application should also add Cache Validators to the response: An ETag header (and Last-Modified header if you know when the resource was last modified). This way the client will also include the ETag and Last-Modified information in the request and the application can check if the client still has the current state.

Revalidate a response

To determine if the client still has a current copy of the page and the response is not modified, you can use the isNotModified method. Simply add the cache headers to the response and then call the method with both the request and the response. The method will automatically compare the If-None-Match header of the request with the ETag header of the response (and/or the If-Modified-Since header of the request with the Last-Modified header of the response if available). If the response is not modified, return the empty response with the cache headers and a status code 304 (Not Modified). This will instruct the client to use the cached copy from the previous request, saving you CPU/memory usage and bandwidth. Therefore it is important to keep the code before the isNotModified call as lightweight as possible to increase performance. Don't create the complete response before this method.

Conditional request with unsafe method

While the procedure described above is usually optional and for safe methods (GET and HEAD), it is also possible to enforce that the client has the current resource state. This is useful for unsafe methods (e.g. POST, PUT, PATCH or DELETE), because it can prevent lost updates (e.g. if another client updates the resource before your request). It is a good idea to initially check if the request includes the appropriate headers (If-Match for an ETag and/or If-Unmodified-Since for a Last-Modified date) with the hasStateValidator method. If the request does not include this information, abort the execution and return status code 428 (Precondition Required) or status code 403 (Forbidden) if you only want to use the original status codes.

If the state validators are included in the request, you can check if the request has the current resource state and not an outdated version with the method hasCurrentState. If the request has an outdated resource state (another ETag or an older Last-Modified date), abort the execution and return status code 412 (Precondition Failed). Otherwise you can continue to process the request and update/delete the resource. Once the resource is updated, it is a good idea to include the updated ETag (and Last-Modified date if available) in the response.

Available helper methods

Method Description (see the phpDoc for more information)
withCache Convenience method to add a Cache-Control header, which allows caching
withCachePrevention Convenience method to prevent caching
withExpires Adds an Expires header from a timestamp, string or DateTime
withRelativeExpires Adds an Expires header with a specific lifetime
withETag Adds an ETag header
withLastModified Adds a Last-Modified header from a timestamp, string or DateTime
withCacheControl Adds a Cache-Control header from a string or value object
hasStateValidator Checks if it is possible to determine the resource state
hasCurrentState Checks if a request has the current resource state
isNotModified Checks if a response is not modified
isCacheable Checks if a response is cacheable by a public cache
isFresh Checks if a response is fresh (age smaller than lifetime)
getLifetime Returns the lifetime of a response (how long it should be cached)
getAge Returns the age of a response (how long it was in the cache)

References

License

The files in this archive are licensed under the BSD-3-Clause license. You can find a copy of this license in LICENSE.md.


All versions of psr7-cache with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
psr/http-message 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 micheh/psr7-cache contains the following files

Loading the files please wait ....