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

Cachebundle Laravel Package

beryllium/cachebundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation Add the bundle via Composer:

    composer require beryllium/cachebundle:dev-master
    

    Or manually via deps file (legacy setups).

  2. Enable the Bundle Register in AppKernel.php:

    new Beryllium\CacheBundle\BerylliumCacheBundle(),
    
  3. Basic Configuration Define Memcache servers in config.yml:

    beryllium_cache:
        servers:
            default:
                host: "127.0.0.1"
                port: 11211
                weight: 1
    
  4. First Use Case Inject the cache service in a controller/service:

    use Beryllium\CacheBundle\Cache\CacheInterface;
    
    class MyController extends Controller
    {
        public function index(CacheInterface $cache)
        {
            $cache->set('key', 'value', 3600); // Store for 1 hour
            $value = $cache->get('key');
            return new Response($value);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Dependency Injection

    • Use the CacheInterface in services/controllers for type-hinted caching:
      public function __construct(CacheInterface $cache) { ... }
      
    • Tag services for lazy-loading (e.g., @cacheable).
  2. Multi-Server Setup Configure multiple server pools in config.yml:

    beryllium_cache:
        servers:
            primary:
                host: "memcache1.example.com"
                port: 11211
            secondary:
                host: "memcache2.example.com"
                port: 11211
    

    Access via:

    $cache->getClient('primary')->get('key');
    
  3. Integration with Symfony Cache Extend Symfony’s Cache component:

    $cache = $this->get('beryllium_cache.cache.default');
    $cache->save($item, $key, ['ttl' => 3600]);
    
  4. Event-Driven Caching Listen for cache events (e.g., beryllium_cache.on_miss):

    services:
        my.cache_listener:
            class: AppBundle\Listener\CacheListener
            tags:
                - { name: kernel.event_listener, event: beryllium_cache.on_miss, method: onCacheMiss }
    
  5. Custom Cache Adapters Implement Beryllium\CacheBundle\Cache\CacheInterface for APC/Redis:

    class ApcCache implements CacheInterface { ... }
    

    Register in services.yml:

    services:
        app.apc_cache:
            class: AppBundle\Cache\ApcCache
            tags:
                - { name: beryllium_cache.cache, alias: apc }
    

Gotchas and Tips

Pitfalls and Debugging

  1. Server Health Checks

    • Issue: Silent failures if a Memcache server is down.
    • Fix: Configure timeout and retry_interval in config.yml:
      beryllium_cache:
          servers:
              default:
                  timeout: 1.5
                  retry_interval: 30
      
    • Debug: Enable logging in config.yml:
      beryllium_cache:
          logging: true
      
  2. Connection Pooling

    • Issue: Stale connections if servers are restarted.
    • Fix: Use persistent_id to maintain connections:
      beryllium_cache:
          servers:
              default:
                  persistent_id: "app_memcache"
      
  3. Namespace Collisions

    • Issue: Keys may clash across environments.
    • Fix: Prefix keys with an environment-specific namespace:
      $cache->set('app_' . $env . '_key', $value);
      
  4. Serialization Quirks

    • Issue: Non-serializable objects (e.g., closures) fail silently.
    • Fix: Use serialize()/unserialize() explicitly:
      $cache->set('key', serialize($object));
      $object = unserialize($cache->get('key'));
      
  5. Configuration Overrides

    • Issue: Local overrides may not apply.
    • Fix: Use %kernel.environment% in config.yml:
      beryllium_cache:
          servers:
              %kernel.environment%_memcache:
                  host: "local-memcache"
      

Extension Points

  1. Custom Cache Drivers Extend Beryllium\CacheBundle\Cache\AbstractCache for new backends (e.g., DynamoDB):

    class DynamoCache extends AbstractCache {
        public function get($key) { ... }
        public function set($key, $value, $ttl) { ... }
    }
    
  2. Middleware for Cache Intercept requests to add cache headers:

    $cache->addMiddleware(function ($request, $next) {
        if ($request->headers->has('X-Cache-Key')) {
            $key = $request->headers->get('X-Cache-Key');
            $response = $cache->get($key);
            return $response ?: $next($request);
        }
        return $next($request);
    });
    
  3. Cache Warmup Pre-load critical data during deployment:

    $cache->warmup([
        'homepage' => $this->renderView('homepage.html.twig'),
        'products' => $this->getProducts(),
    ]);
    
  4. Monitoring Track cache hits/misses via Symfony Profiler:

    $cache->enableProfiler();
    

    View data in /_profiler.

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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor