Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webfactory/webfactoryhttpcachebundle
Symfony bundle to ease HTTP cache validation via last modified header
https://github.com/webfactory/webfactoryhttpcachebundle
bundle cache caching http-cache-bundle httpcache php symfony
Last synced: 28 days ago
JSON representation
Symfony bundle to ease HTTP cache validation via last modified header
- Host: GitHub
- URL: https://github.com/webfactory/webfactoryhttpcachebundle
- Owner: webfactory
- License: mit
- Created: 2018-03-06T15:56:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T18:29:55.000Z (8 months ago)
- Last Synced: 2024-04-29T21:47:10.910Z (7 months ago)
- Topics: bundle, cache, caching, http-cache-bundle, httpcache, php, symfony
- Language: PHP
- Size: 41 KB
- Stars: 2
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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].[HTTP cache validation via the last modified header]: https://symfony.com/doc/current/http_cache/validation.html#validation-with-the-last-modified-header
[symfony/http-kernel package]: https://symfony.com/doc/current/http_cache.html#http-cache-expiration-introThe `#[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:
```php
blogPostRepository->findLatest();
return $post?->getPublishingDate();
}
}
```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:```php
["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:
- @repository_post
`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](LICENSE).