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

Zeta Cache Bundle Laravel Package

aw/zeta-cache-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require aw/zeta-cache-bundle
    

    Add the bundle to app/AppKernel.php:

    new Aw\ZetaCacheBundle\AwZetaCacheBundle(),
    
  2. Configuration: Enable the bundle in app/config/config.yml:

    aw_zeta_cache:
        dev_mode: true  # Set to false in production
        storages:
            default:
                type: file
                path: "%kernel.cache_dir%/zeta"
                options:
                    max_items: 1000
    
  3. First Use Case: Inject the cache service in a controller or service:

    use Aw\ZetaCacheBundle\Service\CacheService;
    
    class MyController extends Controller
    {
        public function indexAction(CacheService $cache)
        {
            $data = $cache->get('my_key');
            if ($data === null) {
                $data = $this->fetchData(); // Expensive operation
                $cache->set('my_key', $data, ['tag1', 'tag2']);
            }
            return $this->render('template.html.twig', ['data' => $data]);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Tag-Based Caching: Use tags to group related cache items for efficient invalidation:

    $cache->set('user_profile_123', $profile, ['user', 'profile']);
    $cache->deleteByTag('user'); // Invalidate all user-related items
    
  2. Hierarchical Caching (Stacks): Define a stack in config.yml to combine multiple backends (e.g., APC + File):

    aw_zeta_cache:
        stacks:
            hybrid:
                storages: [apc, file]
                options:
                    free_rate: 0.2
    

    Use the stack service:

    $cache->getService('hybrid')->set('key', $data);
    
  3. Event-Driven Cache Clearing: Trigger cache invalidation via Symfony events (e.g., kernel.request):

    # config.yml
    aw_zeta_cache:
        event_listeners:
            kernel.request:
                - { storage: 'default', tags: ['user'] }
    
  4. CLI Management: Clear caches via console:

    php app/console aw:zeta-cache:clear --storage=default
    php app/console aw:zeta-cache:delete --tags="user,profile"
    

Integration Tips

  • Symfony Cache Abstraction: Extend CacheInterface to bridge Zeta Cache with Symfony’s Cache component:

    class ZetaCacheAdapter implements CacheInterface {
        public function fetch($id) {
            return $this->zetaCache->get($id);
        }
        // ... other methods
    }
    
  • Dependency Injection: Tag services for automatic cache invalidation:

    services:
        my.service:
            tags: ['aw_zeta_cache.invalidator']
            arguments: ['default', ['tag1', 'tag2']]
    
  • Dev Mode: Enable dev_mode: true to bypass cache entirely during development.


Gotchas and Tips

Pitfalls

  1. Unmaintained Package:

    • No active maintenance; fork or patch critical issues locally.
    • Avoid in production unless you’re prepared to maintain it.
  2. Configuration Overhead:

    • Zeta Cache’s hierarchical stacks require careful tuning of max_items and free_rate to avoid performance degradation.
    • Example: Set free_rate: 0.1 for conservative memory usage.
  3. Race Conditions:

    • Disable "Anti Dog Pile" protection only if you’re certain your app handles concurrent writes safely.
    • Enable it by default in config.yml:
      aw_zeta_cache:
          anti_dog_pile: true
      
  4. Tag Performance:

    • Overusing tags (e.g., per-user tags) can bloat cache metadata. Use sparingly for broad invalidation (e.g., ['user_role']).
  5. APC/Memcache Dependencies:

    • Ensure extensions are installed (php-apc, php-memcache). Fallback to file storage if unavailable:
      storages:
          fallback:
              type: file
              path: "%kernel.cache_dir%/zeta_fallback"
      

Debugging

  • Dev Mode: Set dev_mode: true to force cache misses and test logic without clearing manually.

  • Log Cache Operations: Enable Symfony’s cache profiler (%kernel.debug%: true) to monitor hits/misses.

  • Check Storage Limits: Use the CLI to inspect storage sizes:

    php app/console aw:zeta-cache:info
    

Extension Points

  1. Custom Replacement Strategies: Override the default LRU/LFU by extending Zeta\Cache\Storage\ReplacementStrategy and configuring it in config.yml:

    storages:
        custom:
            type: file
            replacement_strategy: my_custom_strategy
    
  2. New Storage Backends: Implement Zeta\Cache\Storage\StorageInterface and register it via a compiler pass.

  3. Event Listeners: Extend cache invalidation logic by subscribing to aw_zeta_cache.invalidate events:

    // services.yml
    my.invalidator:
        class: AppBundle\EventListener\CacheInvalidator
        tags:
            - { name: kernel.event_listener, event: aw_zeta_cache.invalidate, method: onInvalidate }
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony