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

Memcached Laravel Package

besimple/memcached

Laravel-friendly Memcached integration that simplifies using the PHP Memcached extension for caching and session storage. Provides configuration helpers and adapter glue so your app can talk to Memcached servers with minimal setup.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require besimple/memcached
    

    (Note: Due to lack of maintenance, verify compatibility with your Laravel version.)

  2. Configuration Add to config/cache.php under stores:

    'memcached' => [
        'driver' => 'memcached',
        'host' => env('MEMCACHED_HOST', '127.0.0.1'),
        'port' => env('MEMCACHED_PORT', 11211),
        'prefix' => env('MEMCACHED_PREFIX', 'laravel_'),
        'options' => [
            'retry_interval' => 150,
            'timeout' => 2000,
        ],
    ],
    
  3. First Use Case Cache a value with a 10-minute TTL:

    Cache::put('key', 'value', now()->addMinutes(10));
    $value = Cache::get('key'); // Retrieve
    

Implementation Patterns

Common Workflows

  1. Cache-as-Sidecar Use alongside database queries to reduce load:

    $posts = Cache::remember('posts:latest', now()->addHours(1), function () {
        return Post::latest()->limit(10)->get();
    });
    
  2. Tag-Based Invalidation (If supported; verify via Cache::tags())

    Cache::tags(['users', 'profile'])->put('user:1:profile', $profileData);
    Cache::tags(['users'])->flush(); // Invalidate all tagged keys
    
  3. Fallback Logic

    $data = Cache::remember('expensive:data', now()->addDays(7), function () {
        return ExpensiveOperation::run();
    });
    

Integration Tips

  • Queue Jobs: Cache job payloads to avoid reprocessing:
    Cache::put('job:payload:123', $payload, now()->addMinutes(5));
    
  • API Responses: Cache API responses with Cache-Control headers:
    return Cache::remember('api:users', now()->addMinutes(5), function () {
        return Http::get('https://api.example.com/users');
    });
    

Gotchas and Tips

Pitfalls

  1. No Maintenance

  2. Connection Issues

    • Symptom: Silent failures or stale data.
    • Debug: Check memcached service status (sudo systemctl status memcached) and verify host/port in .env.
  3. Prefix Collisions

    • Issue: Shared Memcached instances may conflict with other apps.
    • Fix: Use a unique prefix (e.g., laravel_app_).

Debugging

  • Inspect Keys:
    $keys = Cache::getStore()->getConnection()->getKeys('laravel_*');
    
  • Clear Cache:
    php artisan cache:clear
    
    (Note: May not work if the package lacks proper Laravel cache integration.)

Extension Points

  • Custom Serialization: Override the serializer via the options array (if supported):
    'options' => [
        'serializer' => new \Memcached\Serializer\JsonSerializer(),
    ],
    
  • Event Listeners: (Unlikely, but if hooks exist, bind to Cache::store events.)

Pro Tips

  • Monitor Memory: Use memcached-tool to check memory usage:
    memcached-tool 127.0.0.1:11211 stats
    
  • Fallback Cache: Combine with file driver for resilience:
    Cache::store('memcached')->remember(...);
    
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