Skip to content
Advertisement

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.

Advertisement

Answer

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.

  • Using the Memcached cache requires the Memcached PECL package to be installed.
  • Using APC cache requires the APC package on your system
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement