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:

First:

Require the MemcachedStore class at the top

<?php 

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

class AppCache
{
	// ...

Second:

Overwrite the createStore() function

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

Third:

?!?$?

Fourth:

Profit.

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

jQuery: Roll to Next Input

I was looking for a way to have an input, that when you change, would roll to the next input. The project I'm working on has a page based system, so each page has its own fieldset. When the last field is completed, I wanted it to automatically roll to the next page. I also wanted functionality for zip code, and phone number fields, that would roll to the next input after 5 digits on zip, or roll to the next piece of the phone number field.