Installation:
composer require dozoisch/cachedbuzz:dev-master
Add the bundle to app/AppKernel.php:
new Dozoisch\CachedBuzzBundle\DozoischCachedBuzzBundle(),
First Use Case:
Replace buzz service calls with dozoisch_cached_buzz.client in your services. Example:
$client = $this->get('dozoisch_cached_buzz.client');
$response = $client->get('https://api.example.com/data');
Default Configuration: The bundle auto-configures with APC caching (falls back to default if APC unavailable). No manual config needed for basic use.
Service Replacement:
Replace buzz.client with dozoisch_cached_buzz.client in your controllers/services. The API remains identical to Buzz.
Cache Invalidation: Use Symfony’s cache system to invalidate entries:
$this->get('dozoisch_cached_buzz.cache')->delete('https://api.example.com/data');
Custom Cache/Validator:
Override defaults via config (app/config/config.yml):
dozoisch_cached_buzz:
cache: 'cache.app' # Use Symfony's cache service
validator: 'my_custom_validator'
Integration with HTTP Clients: Use with Guzzle-like patterns:
$response = $client->request('GET', 'https://api.example.com/data', [
'headers' => ['Accept' => 'application/json']
]);
validator if needed.$client->get('https://api.example.com/uncached', ['cache' => false]);
APC Dependency:
Default cache uses APC. If APC is unavailable, the bundle fails silently (no fallback). Specify a custom cache (e.g., cache.app) in config to avoid this.
Cache Key Collisions: Default key generation may conflict for similar URLs. Extend the validator to customize keys:
services:
my_validator:
class: AppBundle\Validator\CustomCachedBuzzValidator
arguments: ['@dozoisch_cached_buzz.client']
Configuration Overrides:
Ensure dozoisch_cached_buzz config is merged correctly. Use parameters or imports in config.yml if needed.
CACHE_MISS events. Enable Symfony’s cache debug toolbar for visibility.validator service is properly implemented (must extend Dozoisch\CachedBuzzBundle\Validator\CachedBuzzValidatorInterface).Custom Cache Drivers:
Implement Psr\Cache\CacheItemPoolInterface and reference it in config:
dozoisch_cached_buzz:
cache: 'my_cache_service'
Request/Response Filtering: Extend the validator to modify cache logic:
class MyValidator implements CachedBuzzValidatorInterface {
public function isCacheable(RequestInterface $request) {
return $request->getMethod() !== 'POST'; // Skip POST requests
}
}
Event Listeners:
Subscribe to cachedbuzz.response events to post-process responses before caching:
services:
my_cachedbuzz_listener:
class: AppBundle\EventListener\CachedBuzzListener
tags:
- { name: kernel.event_listener, event: cachedbuzz.response, method: onResponse }
How can I help you explore Laravel packages today?