Symfony Reverse Proxy: Memcached

The Background

Basically, we wanted to be able to use a simple Reverse Proxy (not Varnish, not Squid), that used a Memcache installation, instead of the file system.

The Solution - Short

I wrote a new MemcachedStore class that AppCache now uses instead. The biggest downside is, the configs for the servers aren't used by the AppCache piece.

The Solution - Long

Heres the MemcachedStore class. Right now, it's set up to use my AequasiMemcachedBundle Symfony bundle at the moment, but it wouldn't be that hard to change to just using Memcached or Memcache.

Place this file in your app directory.

Then, in app/AppCache.php, do the following:


Require the MemcachedStore class at the top


require_once __DIR__ . '/AppKernel.php';
require_once __DIR__ . '/MemcachedStore.php';

class AppCache
	// ...


Overwrite the createStore() function

class AppCache
    // ...
    public function createStore()
        $servers = [
            [ 'localhost', 11211 ]
        return new MemcachedStore( [
            'enabled'      => true,
            'debug'        => true,
            'persistentId' => serialize( $servers )
        ], $servers );
    // ...





Extra Stuff

If you want to create a service to get to this particular store, you would have to create a $cache variable in your app/AppKernel, and overwrite your app/AppCache's handle() method to set the kernel's $cache variable before calling parent::handle.

Related Posts

Creating a Chrome Extension with NextJS

So, you've delved into writing your own Chrome extension. Maybe you've even already made one, but you still have a question: How can I use more current technology to to this? Well, as it turns out, it only takes a few extra steps!