Giter VIP home page Giter VIP logo

cachebundle's Introduction

BerylliumCacheBundle for Symfony2

It's memcache. You've seen it before. Now it's injectable to the DIC, and you don't have to write all this junk yourself. And it should also work with Amazon ElasticCache, as well as the MySQL Memcache Interface (new in MySQL 5.6).

Another advantage over just using a raw memcache object is that BCB probes servers before adding them to the pool - if a server is down, your site won't be gravely impacted by the Memcache class waiting and waiting and waiting for a response.

The groundwork is also laid out for building alternate cache interfaces quickly - such as APC caching, or your own home-rolled filesystem cache.

Configuration

Step 1: Fetching

If you are using composer, you probably only need to add this to your composer.json file:

"require": {
  "Beryllium/CacheBundle": "dev-master"
},

If you aren't using composer, add this to your deps file:

[BerylliumCacheBundle]
    git=http://github.com/beryllium/CacheBundle.git
    target=/bundles/Beryllium/CacheBundle

And then run the update vendors script:

bin/vendors install

Step 2: Configure autoload.php

If you aren't using Composer, register the namespace like so:

# app/autoload.php

<?php

$loader->registerNamespaces( array(
  //...
  'Beryllium' => __DIR__.'/../vendor/bundles',
  ) );

Step 3: Configure the AppKernel

Add it to your AppKernel:

# app/AppKernel.php

<?php

    $bundles = array(
        //...
        new Beryllium\CacheBundle\BerylliumCacheBundle(),
    );

Configure your server list in parameters.ini:

beryllium_cache.client.servers["127.0.0.1"] = 11211 

Or for parameters.yml:

parameters:
    ...
    beryllium_cache.client.servers: { "localhost": 11211 }

If you plan on using local UNIX sockets, GitHub user gierschv has contributed the ability to do this:

beryllium_cache.client.servers["unix:///tmp/mc.sock"]=""

And then you should be good to go:

$this->get( 'beryllium_cache' )->set( 'key', 'value', $ttl );
$this->get( 'beryllium_cache' )->get( 'key' );

You might want to set up a service alias, since "$this->get( 'beryllium_cache' )" might be a bit long.

The Command Line

For a command line report of CacheClient statistics (assuming the cache client has a ->getStats method, which is not an interface requirement), you can do the following:

app/console cacheclient:stats

Example Output:

Servers found: 1

Host:    127.0.0.1:11211
	Usage: 0% (0.01MB of 64MB)
	Uptime: 344976 seconds (3 days, 23 hours, 49 minutes, 36 seconds)
	Open Connections: 15
	Hits: 26
	Misses: 29
	Helpfulness: 47.27%

Or, for extended information (the raw stats array), you can run with debugging enabled:

app/console cacheclient:stats --debug

Help is available, although brief:

app/console help cacheclient:stats

The Future

Currently there aren't any unit or functional tests. So that needs to be worked on.

More cache client implementations could be useful, if it turns out there's a demand for them.

And yes, the documentation needs to be more thorough as well. I've made some improvements, but it's still spotty at best.

Beyond that, who knows what the future might hold.

Additional Resources

MySQL InnoDB+Memcached API:

Amazon ElastiCache:

cachebundle's People

Contributors

beryllium avatar jeremylivingston avatar gierschv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.