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

Doctrine Cache Bundle Laravel Package

liip/doctrine-cache-bundle

Deprecated Symfony2 bundle integrating Doctrine Common Cache. Defines cache services via config with namespaces, types (APC, filesystem, memcached), directories/hosts/ports, and aliases. Use doctrine/doctrine-cache-bundle instead.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require liip/doctrine-cache-bundle:~1.0
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Liip\DoctrineCacheBundle\LiipDoctrineCacheBundle::class => ['all' => true],
    ];
    
  2. Basic Configuration (config/packages/liip_doctrine_cache.yaml):

    liip_doctrine_cache:
        namespaces:
            default:
                type: apc
    
  3. First Use Case: Inject the cache service into a controller/service:

    use Doctrine\Common\Cache\Cache;
    
    class MyService
    {
        public function __construct(private Cache $cache)
        {
        }
    
        public function fetchData()
        {
            $data = $this->cache->fetch('my_key');
            if ($data === null) {
                $data = $this->generateData();
                $this->cache->save('my_key', $data, 3600); // Cache for 1 hour
            }
            return $data;
        }
    }
    

Implementation Patterns

Common Workflows

  1. Multi-Cache Namespaces: Use distinct namespaces for different data types (e.g., users, products):

    liip_doctrine_cache:
        namespaces:
            users:
                type: memcached
                host: memcached
            products:
                type: file_system
                directory: "%kernel.cache_dir%/products"
    
  2. Dependency Injection: Define services with cache dependencies in config/services.yaml:

    services:
        App\Service\ProductService:
            arguments:
                $cache: '@liip_doctrine_cache.ns.products'
    
  3. Doctrine Integration: Configure Doctrine to use the cache for queries (config/packages/doctrine.yaml):

    doctrine:
        orm:
            metadata_cache_driver: liip_doctrine_cache.ns.metadata
            query_cache_driver: liip_doctrine_cache.ns.queries
            result_cache_driver: liip_doctrine_cache.ns.results
    
  4. Environment-Specific Caching: Override cache types in config/packages/dev/liip_doctrine_cache.yaml:

    liip_doctrine_cache:
        namespaces:
            default:
                type: array  # Resets per request in dev
    

Integration Tips

  • Symfony Cache Adapter: Use symfony/cache for modern alternatives (e.g., Psr6Cache).
  • Cache Warmup: Preload critical caches during deployment:
    $cache->save('critical_data', $data, 86400); // Cache for 1 day
    
  • TTL Strategies: Dynamically set TTLs based on data volatility:
    $ttl = $isVolatile ? 60 : 86400; // 1 min or 1 day
    $cache->save('key', $data, $ttl);
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warning:

  2. APCu Limitations:

    • APCu caches are request-scoped in PHP-FPM. Use file_system or memcached for shared caching.
    • APCu may fail silently if the extension is disabled.
  3. Memcached Configuration:

    • Ensure the id service (e.g., my_memcached_service) is properly configured in Symfony’s DI container.
    • Default port/host may not match your Memcached setup.
  4. File System Permissions:

    • Verify the directory path is writable by the web server user (e.g., www-data):
      chmod -R 775 /tmp/lala
      
  5. Namespace Collisions:

    • Avoid reusing namespaces across different cache types (e.g., default for both APCu and Memcached).

Debugging

  • Check Cache Hits/Misses: Implement a wrapper to log cache operations:

    $cache->save('key', $data);
    // Log: "Cache miss for 'key' (saved)"
    
  • Clear Caches: Manually delete files in file_system caches or flush APCu:

    apcu_clear_cache()  # Requires APCu extension
    
  • Validate Configuration: Use Symfony’s debug toolbar or bin/console debug:container to verify cache services are registered.

Extension Points

  1. Custom Cache Drivers: Create a service implementing Doctrine\Common\Cache\Cache:

    services:
        app.custom_cache:
            class: App\Cache\RedisCache
            arguments:
                - '@redis.client'
            tags: ['liip_doctrine_cache.type', { name: 'redis' }]
    

    Then use it in config:

    liip_doctrine_cache:
        namespaces:
            redis_cache:
                type: redis
    
  2. Cache Events: Listen for cache saves/misses via Symfony events (if using a wrapper class).

  3. Fallback Strategies: Combine caches (e.g., array as fallback for file_system):

    if (($data = $primaryCache->fetch('key')) === null) {
        $data = $fallbackCache->fetch('key');
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
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