Control of cache headers

The cache headers for a feed request can be influenced with the class attribute Brotkrueml\FeedGenerator\Attributes\Cache. One can pass the number in seconds that a feed should be cached by a browser or feed reader:

EXT:your_extension/Classes/Feed/YourFeed.php
// use Brotkrueml\FeedGenerator\Attributes\Cache

#[Feed('/your-feed.atom', FeedFormat::ATOM])]
#[Cache(3600)] // Cache for one hour
final class YourFeed implements FeedInterface
{
   // ...
}
Copied!

To clarify that the number stands for seconds, you can also use a named argument:

EXT:your_extension/Classes/Feed/YourFeed.php
// use Brotkrueml\FeedGenerator\Attributes\Cache

#[Feed('/your-feed.atom', FeedFormat::ATOM)]
#[Cache(seconds: 3600)] // Cache for one hour
final class YourFeed implements FeedInterface
{
   // ...
}
Copied!

Both examples will result in the following HTTP headers:

Cache-Control: max-age=3600
Expires: Mon, 20 Jun 2022 08:06:03 GMT
Copied!

If you want to define the cache headers for all available feeds, you can also set them directly in the configuration of your Apache web server according to the content type:

.htaccess
# Apache module "mod_expires" has to be active

# For Atom feeds
ExpiresByType application/atom+xml "access plus 1 hour"
# For JSON feeds
ExpiresByType application/feed+json "access plus 1 hour"
# For RSS feeds
ExpiresByType application/rss+xml "access plus 1 hour"
Copied!