phplaravellaravel-5memcachedapc

How to use memcached and apc together in laravel?


I want to use both memcached and apc at the same time for caching, how can I configure and use it in laravel.


Solution

  • By using the Cache facade you can specify what cache type you want to use.

    Cache::store('memcached')->put('bar', 'baz', 10); // Using memcached
    Cache::store('apc')->put('bar', 'baz', 10); // Using apc
    

    As you can see in your app/config/cache.php there is already some preconfigured cache types set up:

    'stores' => [
    
            'apc' => [
                'driver' => 'apc',
            ],
    
            'array' => [
                'driver' => 'array',
            ],
    
            'database' => [
                'driver' => 'database',
                'table' => 'cache',
                'connection' => null,
            ],
    
            'file' => [
                'driver' => 'file',
                'path' => storage_path('framework/cache'),
            ],
    
            'memcached' => [
                'driver' => 'memcached',
                'servers' => [
                    [
                        'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                        'port' => env('MEMCACHED_PORT', 11211),
                        'weight' => 100,
                    ],
                ],
            ],
    
            'redis' => [
                'driver' => 'redis',
                'connection' => 'default',
            ],
    
        ],
    

    You now need to make sure, memcached and APC are correctly installed on your system.