dreadlabs/kunstmaan-distributed-bundle
Installation
Add the bundle to composer.json:
composer require dreadlabs/kunstmaan-distributed-bundle
Register it in config/bundles.php (Laravel) or AppKernel.php (Symfony):
DreadLabs\KunstmaanDistributedBundle\DreadLabsKunstmaanDistributedBundle::class => ['all' => true],
Configure Redis Add Redis dependencies:
composer require snc/redis-bundle predis/predis doctrine/doctrine-cache-bundle
Define Redis connection in config/packages/snc_redis.yaml (Laravel) or config.yml (Symfony):
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost:6379
Set Parameters
Update config/packages/parameters.yaml (Laravel) or parameters.yml (Symfony):
parameters:
http_cache_purge_client_ips: ['127.0.0.1', '192.168.1.100'] # Trusted IPs for cache purge
http_cache_proxy_servers: ['localhost:80'] # Proxy servers
http_cache_proxy_baseurl: 'https://yourdomain.com' # Base URL
http_cache_purge_method: 'PURGE' # Custom HTTP method
redis_host: 'localhost' # Redis host
First Use Case Deploy Kunstmaan CMS on a clustered setup (e.g., multiple web servers). The bundle ensures:
PURGE requests.Clustered Deployment
snc_redis for high availability (e.g., Redis Sentinel or Cluster).Cache Invalidation
PURGE requests from trusted clients (defined in http_cache_purge_client_ips).use Symfony\Component\HttpFoundation\Request;
public function purgeCache(Request $request)
{
if ($request->isMethod('PURGE') && in_array($request->getClientIp(), $this->getParameter('http_cache_purge_client_ips'))) {
$this->get('kunstmaan_admin.cache')->invalidateAll();
}
return new Response('Cache purged', 200);
}
Event-Driven Cache Updates
dreadlabs_kunstmaan_distibuted.cache_page_events.subscriber to listen to Kunstmaan events (e.g., PageUpdateEvent) and invalidate cache automatically:
// config/packages/kunstmaan_admin.yaml
kunstmaan_admin:
cache:
page_events_subscriber: true
Customizing Proxy Behavior
PurgeCacheListener:
// src/EventListener/CustomPurgeCacheListener.php
use DreadLabs\KunstmaanDistributedBundle\EventListener\PurgeCacheListener as BaseListener;
class CustomPurgeCacheListener extends BaseListener
{
public function onKernelRequest(GetResponseEvent $event)
{
// Custom logic here
parent::onKernelRequest($event);
}
}
services.yaml:
services:
App\EventListener\CustomPurgeCacheListener:
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Redis Connection Issues
redis_host and snc_redis configurations match your infrastructure.php bin/console debug:container snc_redis.default
Cache Invalidation Delays
curl -X PURGE http://yourdomain.com/path -H "X-Forwarded-For: 127.0.0.1"
HTTP PURGE Method Blocking
PURGE:
if ($request_method = PURGE) {
return 200;
}
X-Cache-Purge) and modify the bundle’s PurgeCacheListener.Compiler Pass Conflicts
kunstmaan_admin.cache compiler pass may conflict with other cache bundles.# config/packages/dreadlabs_kunstmaan_distributed.yaml
dreadlabs_kunstmaan_distributed:
enable_cache_compiler_pass: false
Monitor Redis Performance
redis-cli monitor to track cache operations in real-time.appendfsync everysec) for clustered setups.Environment-Specific Configs
config/packages/parameters.dev.yaml):
parameters:
redis_host: 'redis-dev.example.com'
http_cache_purge_client_ips: ['10.0.0.1/24'] # Dev network
Testing Cache Invalidation
$this->container->set('snc_redis.default', $this->createMock(\Predis\Client::class));
$this->container->get('event_dispatcher')->dispatch(new PageUpdateEvent($page));
Extending Cache Keys
CacheKeyGenerator:
// config/packages/kunstmaan_admin.yaml
kunstmaan_admin:
cache:
cache_key_generator: App\Service\CustomCacheKeyGenerator
Logging Cache Operations
# config/packages/monolog.yaml
handlers:
cache:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.cache.log"
level: debug
channels: ["kunstmaan_admin.cache"]
How can I help you explore Laravel packages today?