2017 © Pedro Peláez
 

library laravel-memcached-plus

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

image

windevalley/laravel-memcached-plus

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  • Wednesday, October 14, 2015
  • by windevalley
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

laravel-memcached-plus

Summary

Integrating with cloud memcached services such as MemCachier and memcached cloud can require memcached features not available with the built-in Laravel 5 Cache memcached driver., (*1)

These include:, (*2)

  • SASL authentication
  • custom options
  • persistent connections

Adding 3 new configuration items, this package enhances the built-in Laravel 5 Cache memcached driver. Optionally, this package also allows these extra configuration items to be used for memcached Sessions., (*3)

Read on for detailed instructions - you may find it useful to reference the demo app at the same time., (*4)

Update: see here for details on the PRs I submitted to laravel/framework., (*5)

Requirements

Installation

Available to install as a Composer package on Packagist, all you need to do is:, (*6)

composer require b3it/laravel-memcached-plus, (*7)

If your local environment does not meet the requirements you may need to append the ignore-platform-reqs option:, (*8)

composer require b3it/laravel-memcached-plus --ignore-platform-reqs, (*9)

Configuration

Once installed you can use this package to enhance the Laravel Cache and Session services., (*10)

Providers

This section discusses the Laravel application configuration file app/config.php., (*11)

In the providers array you need to replace following built-in Service Providers:, (*12)

  • Illuminate\Cache\CacheServiceProvider and (optionally)
  • Illuminate\Session\SessionServiceProvider

A recommended approach is to comment out the built-in providers and append the Service Providers from this package:, (*13)

'providers' => [
    ...
    //'Illuminate\Cache\CacheServiceProvider',
    ...
    //'Illuminate\Session\SessionServiceProvider',
    ...

    /*
     * Application Service Providers...
     */
     ...

    'B3IT\MemcachedPlus\CacheServiceProvider',
    'B3IT\MemcachedPlus\SessionServiceProvider',
],

On a fresh install of Laravel 5.0.13 the providers array is on line 111 of app/config.php., (*14)

The B3IT\MemcachedPlus\SessionServiceProvider is optional. You only need to add this if:, (*15)

  • You want to specify the memcached store to use for sessions, or
  • You want to use the memcached features provided by this package for sessions

Cache

This section discusses the Laravel cache configuration file config/cache.php., (*16)

This package makes the following extra configuration items are available for use with a memcached store:, (*17)

These may be used in a store config like so:, (*18)

'stores' => [
    'memcachedstorefoo' => [
        'driver'  => 'memcached',
        'persistent_id' => 'laravel',
        'sasl'       => [
            env('MEMCACHIER_USERNAME'),
            env('MEMCACHIER_PASSWORD')
        ],
        'options'    => [
            'OPT_NO_BLOCK'         => true,
            'OPT_AUTO_EJECT_HOSTS' => true,
            'OPT_CONNECT_TIMEOUT'  => 2000,
            'OPT_POLL_TIMEOUT'     => 2000,
            'OPT_RETRY_TIMEOUT'    => 2,
        ],
        'servers' => [
            [
                'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
            ],
        ],
    ],
],

When defining options you should set the config key to the Memcached constant name as a string. This avoids any issues with local environments missing ext-memcached and throwing a warning about undefined constants. The config keys are automatically resolved into Memcached constants by the MemcachedPlus\MemcachedConnector which throws a RuntimeException if the constant is invalid., (*19)

Note that as this package enhances the built-in Laravel 5 memcached Cache driver the driver string remains memcached., (*20)

In case you are unfamiliar with how to use multiple cache stores in Laravel, you would access this store from your application code like so:, (*21)

$value = Cache::store('memcachedstorefoo')->get('key');

Session

This section discusses the Laravel session configuration file config/session.php., (*22)

If you are using memcached sessions you will have set the driver configuration item to 'memcached'., (*23)

If you have added the B3IT\MemcachedPlus\SessionServiceProvider as discussed above, the memcached_store configuration item is available. This is explained in the following new snippet you can paste into your session configuration file:, (*24)

    /*
    |--------------------------------------------------------------------------
    | Session Cache Store
    |--------------------------------------------------------------------------
    |
    | When using the "memcached" session driver, you may specify a cache store
    | that should be used for these sessions. This should correspond to a
    | store in your cache configuration options which uses the memcached
    | driver.
    |
    */

    'memcached_store' => 'memcachier',

laravel-memcached-plus in action

I created a demo app for you to see how this package integrates with Laravel 5 and how you could run it on Heroku., (*25)

Integration with laravel/framework

I submitted 2 PRs to laravel/framework to integrate this package in to the framework itself: * Memcached persistent connections, SASL authentication and custom options: #7987 and * Memcached Session store configuration #7988, (*26)

However @taylorotwell closed them due to lack of tests. When time permits I'm planning to add tests and re-submit, but in the meantime if anyone wishes to contribute them please submit a PR., (*27)

Support

Please do let me know if you have any comments or queries., (*28)

Thanks!, (*29)

The Versions

14/10 2015

dev-master

9999999-dev

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

06/03 2015

2.1.5

2.1.5.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

06/03 2015

2.1.4

2.1.4.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

05/03 2015

2.1.3

2.1.3.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

05/03 2015

2.1.2

2.1.2.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

05/03 2015

2.1.1

2.1.1.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

05/03 2015

2.1.0

2.1.0.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

05/03 2015

2.0.0

2.0.0.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

04/03 2015

1.0.1

1.0.1.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud

04/03 2015

1.0.0

1.0.0.0

Extends the built-in Laravel 5 Cache Memcached driver adding support for persistent connections, SASL and Memcached options.

  Sources   Download

MIT

The Requires

 

by Tom Castleman

laravel cache memcached persistent options memcachier heroku sasl memcachedcloud