creative-web-solution/cws-sonata-cache-managing-bundle
Installation
Add the bundle to your composer.json:
composer require creative-web-solution/cws-sonata-cache-managing-bundle
Register it in config/bundles.php:
return [
// ...
Cws\Bundle\SonataCacheManagingBundle\CwsSonataCacheManagingBundle::class => ['all' => true],
];
First Use Case After installation, clear your cache:
php bin/console cache:clear
Navigate to your Sonata Admin Dashboard → A new "Cache" menu item appears under the System section (or similar, depending on your admin theme).
cache:clear, cache:pool:clear) via the UI.Cache Management via UI
Integration with Sonata Admin
ROLE_SUPER_ADMIN only).
# config/packages/security.yaml
access_control:
- { path: ^/admin/cache, roles: ROLE_SUPER_ADMIN }
Programmatic Extensions
// src/Service/CustomCacheProvider.php
class CustomCacheProvider extends BaseCacheProvider
{
public function getPools(): array
{
return array_merge(parent::getPools(), [
'custom_pool' => 'Custom Pool Name',
]);
}
}
Register the service in services.yaml:
services:
Cws\Bundle\SonataCacheManagingBundle\Cache\CacheProviderInterface: '@custom_cache_provider'
Event-Driven Clearing
// src/EventListener/CacheClearListener.php
class CacheClearListener
{
public function onEntityUpdate(EntityUpdateEvent $event)
{
$this->cacheManager->clearPool('sonata.cache.pool');
}
}
Bundle Compatibility
Cache Pool Discovery
cache.app, cache.pool, etc.), but custom pools (e.g., from other bundles) may not appear. Extend the provider as shown above.Performance Impact
php bin/console cache:pool:clear cache.app
Permission Issues
bundles.php.ROLE_ADMIN).# config/packages/monolog.yaml
handlers:
cache:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.cache.log"
level: debug
php bin/console debug:cache to list available pools and verify the bundle’s output matches.Custom Templates Override the cache management template:
# templates/CwsSonataCacheManagingBundle/cache/index.html.twig
{% extends '@CwsSonataCacheManaging/cache/index.html.twig' %}
Add custom buttons or metrics (e.g., cache TTL warnings).
API Endpoints Expose cache clearing via API (e.g., for headless admin):
// src/Controller/CacheController.php
class CacheController extends AbstractController
{
public function clearPool(CacheManagerInterface $cacheManager, string $pool)
{
$cacheManager->clearPool($pool);
return new JsonResponse(['status' => 'cleared']);
}
}
Webhook Triggers Integrate with external services (e.g., Slack alerts for cache failures) by extending the bundle’s event system.
How can I help you explore Laravel packages today?