Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Memcached service for Symfony
PHP
Branch: master

This branch is 9 commits behind tarjei:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
DependencyInjection
Resources
MemcacheFactory.php
MockMemcache.php
README.rst
SMMemcacheBundle.php
composer.json

README.rst

MemcacheBundle

This is a simple bundle that creates a memcached service that you can use.

Note: The service supports creating both PHP Memcache extensions (i.e. both http://php.net/memcache and http://php.net/memcached), BUT it does not protect you from differences in the two services interfaces as it returns the raw object.

Instalation

Add to deps:

[SMMemcacheBundle]
    git=git://github.com/tarjei/MemcacheBundle.git
    target=/bundles/SM/MemcacheBundle

Then register the bundle with your kernel:

// app/AppKernel.php
// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new SM\MemcacheBundle\SMMemcacheBundle(),
    // ...
);

Make sure that you also register the namespaces with the autoloader:

// app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'SM\\MemcacheBundle' => __DIR__ . '/../vendor/bundles',
));

Configuration

In your prod/dev environment:

# app/config/config.yml
sm_memcache:
    use_mock: false
    port: 11211
    host: localhost

In your test environment:

# app/config/config.yml
sm_memcache:
    use_mock: true

Usage

The service is named sm_memcache, it returns a normal Memcache or Memcached php object:

$memcached = $container->get("sm_memcache");
$memcached->set("someKey", "somevalue");

The service is just the normal Memcache object (http://php.net/memcache) so you can use the normal methods.

For tests there is a special MockMemcache object that you can use to stub out the memcache service.

TODO

  • Support multiple memcache servers.
  • Support more methods in the mock module.
Something went wrong with that request. Please try again.