Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cws Sonata Cache Managing Bundle Laravel Package

creative-web-solution/cws-sonata-cache-managing-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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).

    • View cache status (size, entries, etc.).
    • Clear specific caches (e.g., cache:clear, cache:pool:clear) via the UI.

Implementation Patterns

Workflows

  1. Cache Management via UI

    • Bulk Actions: Clear multiple cache pools at once (e.g., all Doctrine, Symfony, or custom pools).
    • Selective Clearing: Target specific cache keys or pools without running CLI commands.
    • Monitoring: Track cache size and hit/miss ratios in real-time (if the bundle exposes metrics).
  2. Integration with Sonata Admin

    • Custom Groups: Extend the bundle to group cache pools (e.g., "Database," "Templates," "API").
    • Permissions: Restrict cache access to specific roles (e.g., ROLE_SUPER_ADMIN only).
      # config/packages/security.yaml
      access_control:
          - { path: ^/admin/cache, roles: ROLE_SUPER_ADMIN }
      
  3. Programmatic Extensions

    • Add Custom Cache Pools: Override the bundle’s cache provider to include non-standard pools (e.g., Redis, Memcached).
      // 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'
      
  4. Event-Driven Clearing

    • Trigger cache clears via Symfony events (e.g., after entity updates).
      // src/EventListener/CacheClearListener.php
      class CacheClearListener
      {
          public function onEntityUpdate(EntityUpdateEvent $event)
          {
              $this->cacheManager->clearPool('sonata.cache.pool');
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Bundle Compatibility

    • Sonata Version Lock: The bundle may not support newer SonataAdmin versions (last release: 2022). Test thoroughly or fork the bundle.
    • Symfony 6+: If using Symfony 6+, check for autowiring conflicts or deprecated service IDs.
  2. Cache Pool Discovery

    • Missing Pools: The bundle auto-discovers Symfony’s default pools (cache.app, cache.pool, etc.), but custom pools (e.g., from other bundles) may not appear. Extend the provider as shown above.
  3. Performance Impact

    • Large Caches: Clearing huge caches via UI may time out. Use CLI for bulk operations:
      php bin/console cache:pool:clear cache.app
      
  4. Permission Issues

    • 403 Errors: If the "Cache" menu disappears, verify:
      • The bundle is enabled in bundles.php.
      • Your user has the correct role (e.g., ROLE_ADMIN).

Debugging

  • Log Cache Actions: Enable debug mode to log cache operations:
    # config/packages/monolog.yaml
    handlers:
        cache:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.cache.log"
            level: debug
    
  • Check Pool Names: Use php bin/console debug:cache to list available pools and verify the bundle’s output matches.

Extension Points

  1. 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).

  2. 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']);
        }
    }
    
  3. Webhook Triggers Integrate with external services (e.g., Slack alerts for cache failures) by extending the bundle’s event system.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware