alengo/sulu-bunny-cdn-bundle
Installation Add the bundle via Composer:
composer require alengo/sulu-bunny-cdn-bundle
Enable it in config/bundles.php:
Alengo\SuluBunnyCdnBundle\SuluBunnyCdnBundle::class => ['all' => true],
Configuration Publish the default config:
php bin/console sulu-bunny-cdn:install
Update config/packages/sulu_bunny_cdn.yaml with your BunnyCDN credentials:
alengo_sulu_bunny_cdn:
api_key: '%env(BUNNY_API_KEY)%'
storage_zone: 'your-storage-zone'
First Use Case Trigger a cache purge after content updates:
use Alengo\SuluBunnyCdnBundle\Service\BunnyCdnPurger;
class YourContentController {
public function updateContent(BunnyCdnPurger $purger) {
// Update content in Sulu/Symfony
$purger->purgeByTag('content-updated'); // Purges all cached assets tagged with 'content-updated'
}
}
Tagging Assets
Use the BunnyCdnTagger service to attach tags to responses:
$response = $this->getContentResponse();
$response = $tagger->addTag($response, 'content-updated');
return $response;
Purging Strategies
$purger->purgeWildcard('*.jpg'); // Purges all JPG files
$purger->purgeByTag('homepage-assets'); // Purges all assets tagged with 'homepage-assets'
Integration with FOSHttpCache
The bundle hooks into FOSHttpCache’s CacheWarmer. Extend the default warmer:
# config/packages/fos_http_cache.yaml
fos_http_cache:
warmer:
Alengo\SuluBunnyCdnBundle\CacheWarmer\BunnyCdnCacheWarmer: ~
Sulu CMS Integration
Override Sulu’s ContentCacheWarmer to include BunnyCDN purges:
use Alengo\SuluBunnyCdnBundle\Service\BunnyCdnPurger;
class CustomContentCacheWarmer extends \Sulu\Bundle\CoreBundle\CacheWarmer\ContentCacheWarmer {
public function __construct(BunnyCdnPurger $purger) {
$this->purger = $purger;
}
public function warmUp($cacheDir) {
parent::warmUp($cacheDir);
$this->purger->purgeByTag('sulu-content'); // Purge after Sulu content updates
}
}
API Key Permissions Ensure your BunnyCDN API key has purge permissions for the storage zone. Test with:
php bin/console debug:container alengo_sulu_bunny_cdn.bunny_cdn_client
Then call:
$client->purge('test-tag');
to verify connectivity.
Tagging Overhead Avoid excessive tagging (e.g., per-request tags). Use semantic tags like:
homepage-assetsproduct-page-{id}global-headerWildcard Purges Are Expensive
Wildcard purges (*.png) trigger full scans of the storage zone. Prefer tag-based purges where possible.
FOSHttpCache Conflicts
If using both sulu_http_cache and fos_http_cache, ensure the BunnyCdnCacheWarmer is only registered once to avoid duplicate purges.
Log Purge Requests
Enable debug logging in config/packages/sulu_bunny_cdn.yaml:
alengo_sulu_bunny_cdn:
debug: true
Check logs for failed purges (e.g., invalid tags or API errors).
Verify Tags in BunnyCDN Dashboard Navigate to your BunnyCDN storage zone → Cache → Tags to confirm tags are applied.
Test Locally with Mock Client Override the client in tests:
$container->set('alengo_sulu_bunny_cdn.bunny_cdn_client', $mockClient);
Custom Purge Logic
Extend BunnyCdnPurger to add conditional purges:
class CustomPurger extends BunnyCdnPurger {
public function purgeIfNeeded(string $tag, bool $condition) {
if ($condition) {
$this->purgeByTag($tag);
}
}
}
Dynamic Tag Generation Generate tags based on Sulu content:
$tag = 'product-'.$product->getId();
$tagger->addTag($response, $tag);
Webhook-Based Purges Use BunnyCDN’s webhook system to trigger purges externally (e.g., from a CI/CD pipeline):
# config/packages/sulu_bunny_cdn.yaml
alengo_sulu_bunny_cdn:
webhook_secret: '%env(BUNNY_WEBHOOK_SECRET)%'
Then implement a controller to handle webhook payloads.
How can I help you explore Laravel packages today?