Download the PHP package webfactory/http-cache-bundle without Composer

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

WebfactoryHttpCacheBundle

WebfactoryHttpCacheBundle is a Symfony bundle that features a more powerful HTTP cache validation via the last modified header than the #[Cache] attribute contained in the symfony/http-kernel package.

The #[ReplaceWithNotModifiedResponse] attribute lets you write small LastModifiedDeterminators for each one of the underlying resources of the requested page. They can be reused and combined freely and can even be defined as services.

Consider this controller code:

When Symfony's routing has chosen this controller action, all of the LastModifiedDeterminators are called to return their respective last modified date.

In this case, both LastModifiedDeterminators are configured as services: @app_caching_post and @app_caching_latest_posts. The first one returns the update date of the requests $post, the second one may use the PostRepository injected from the DI container to return the last update date of the x latest posts.

#[ReplaceWithNotModifiedResponse] combines all of the LastModifiedDeterminators dates to determine to last modified date of the overall page. Finally, if the request contains an appropriate if-not-modified-since header, the execution of the controller action will be skipped and an empty response with a "304 Not Modified" status code will be sent. If your LastModifiedDeterminators are fast, this can improve your performance greatly.

What we like about the LastModifiedDeterminators is that they encourage to separate the concerns nicely and encapsulate the tasks into small units that are easy to understand, reusable and unit test.

Note: #[ReplaceWithNotModifiedResponse] does not alter or add Cache-Control header settings. So, by default your response will remain private and end up in browser caches only. If you want it to be kept in surrogate caches (like Varnish or the Symfony Http Cache), you can add #[Cache(smaxage: 0)]. This will make the response public, but also requires a revalidation on every request as the response is always considered stale. Learn more about Symonfy's HTTP caching.

Usage

Choose a controller action you want to possibly replace with a 304 Not Modified response. Write one LastModifiedDeterminator for each of the different underlying resources, implementing the Webfactory\HttpCacheBundle\NotModified\LastModifiedDeterminator interface.

You can use the $request in the getLastModified e.g. to get route parameters, which is necessary e.g. if you have some filters coded in the requested URL.

If your LastModifiedDeterminator has dependencies you'd like to be injected, configure it as a service.

Then, add the #[ReplaceWithNotModifiedResponse] attribute to the chosen controller method and parameterize it with your LastModifiedDeterminators:

The most simple form of adding a LastModifiedDeterminator is passing its fully qualfified class name:

#[ReplaceWithNotModifiedResponse([\App\Caching\MySimpleLastModifiedDeterminator::class])]

If your LastModifiedDeterminator needs simple constructor arguments, you can pass them in array form:

#[ReplaceWithNotModifiedResponse([\App\Caching\MyLastModifiedDeterminator::class => ["key1" => 1, "key2" => ["*"]]])]

This would pass the array ['key1' => 1, 'key2' => ['*']] as an argument to MyLastModifiedDeterminator's constructor.

If your LastModifiedDeterminator has more sophisticated dependencies, you can define the LastModifiedDeterminator as a service, e.g.:

`yaml // services.yml services: app_caching_latest_posts: class: App\Caching\PostsLastModifiedDeterminator arguments:

and put the service name into the attribute:

#[ReplaceWithNotModifiedResponse(["@app_caching_latest_posts"])]

To combine multiple LastModifiedDeterminators, simply add all of them to the attribute:

#[ReplaceWithNotModifiedResponse([
    "@app_caching_latest_posts",
    \App\Caching\MySimpleLastModifiedDeterminator::class,
    [\App\Caching\MyLastModifiedDeterminator::class => ["key1" = 1, "key2" => ["*"]]
])]

The latest last modified date determines the last modified date of the response.

Credits, Copyright and License

This bundle was started at webfactory GmbH, Bonn.

Copyright 2018-2024 webfactory GmbH, Bonn. Code released under the MIT license.


All versions of http-cache-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
symfony/config Version ^5.0 | ^6.0 | ^7.0
symfony/dependency-injection Version ^5.0 | ^6.0 | ^7.0
symfony/deprecation-contracts Version ^2.0|^3.0
symfony/http-foundation Version ^5.0 | ^6.0 | ^7.0
symfony/http-kernel Version ^5.3 | ^6.0 | ^7.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 webfactory/http-cache-bundle contains the following files

Loading the files please wait ....