GithubHelp home page GithubHelp logo

memcacheserviceprovider's Introduction

Memcache service provider for Silex 2.x

Build Status Total Downloads

It provides access to :

  • a simple Memcache wrapper with very simple API for standard use,
  • or your own Memcache wrapper with $app injection for custom use,
  • or a genuine Memcache(d) object for advanced use.

Installation

Create a composer.json in your projects root-directory :

{
    "require": {
        "kuikui/memcache-service-provider": "~2.0"
    }
}

and run :

$ curl -sS http://getcomposer.org/installer | php
$ php composer.phar install

Registering

$app->register(new KuiKui\MemcacheServiceProvider\ServiceProvider());

Example

$app->register(new KuiKui\MemcacheServiceProvider\ServiceProvider());

// Simple use
$app['memcache']->set('key', 'value');
$value = $app['memcache']->get('key');
$app['memcache']->delete('key');

// Advanced use : use \Closure to generate default value and save it during a retrieve process
$value = $app['memcache']->get('key', function() use ($app) {
    return $app['some_other_service']->getData();
});

Options

After registration, you can customize the service with these options :

Connections

Allows you to set up one or more Memcache connections.
Each connection should be defined as follows array('ip_address', port).

$app['memcache.connections'] = array(
    array('127.0.0.1', 11211),
    array('10.0.1.118', 12345)
; // default: array('127.0.0.1', 11211)

Class

Allows you to choose between the two PHP Memcache libraries : \Memcache or \Memcached.

$app['memcache.class'] = '\Memcached'; // default: '\Memcache'

Wrapper

  • By default, you access to an instance of KuiKui\MemcacheServiceProvider\SimpleWrapper.
  • For custom needs, you can use your own wrapper :
$app['memcache.wrapper'] = '\My\Custom\Wrapper';
  • Or you can have direct acces to Memcache(d) object :
$app['memcache.wrapper'] = false;

Duration

If you use SimpleWrapper, you can configure the default duration of cached data (in seconds):

$app['memcache.default_duration'] = 60; // default: 0 (no limit)

Running the tests

The development environment is provided by Vagrant and the Xotelia box.

$ cp Vagrantfile.dist Vagrantfile
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ composer install
$ ./vendor/bin/atoum

Dependencies

PHP 5.5+

MemcacheServiceProvider needs one of these PHP modules to be installed :

Credits

Deeply inspired by MemcacheServiceProvider from Rafał Filipek.
Tested with atoum.

License

The MemcacheServiceProvider is licensed under the MIT license.

memcacheserviceprovider's People

Contributors

damien-qc avatar kuikui avatar makusu avatar soebbing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

memcacheserviceprovider's Issues

Interface 'Pimple\ServiceProviderInterface' not found

Hi,
I have some error:

PHP Fatal error: Interface Pimple\ServiceProviderInterface not found in /vendor/kuikui/memcache-service-provider/src/KuiKui/MemcacheServiceProvider/ServiceProvider.php on line 23

Maybe use Pimple\ServiceProviderInterface;
must be replaced with use Silex\ServiceProviderInterface;

Fatal error in ServiceProvider

Hi,

I have a server on PHP 5.3.10-1ubuntu3.8 with the following Memcached version:

memcached support enabled
Version 1.0.2
libmemcached version 0.44
Session support yes
igbinary support no

I agree, it's a little bit outdated but would there be a specific reason why the following error might be thrown:

PHP Fatal error:  Using $this when not in object context in vendor/kuikui/memcache-service-provider/src/KuiKui/MemcacheServiceProvider/ServiceProvider.php on line 26

Thanks,
Luke

Incorrect (not ideal) composer instructions

{
    "require": {
        "kuikui/memcache-service-provider": "*"
    }
}

The above code won't resolve to a version (at least on the latest version of composer). If you want users to install the latest version from master, then it should be set to "dev-master".

A more preferable approach would be creating a version tag, and only updating the README when there is a new stable tag.

Tag a release

Can you create a release please? I'm using this in a few projects, and this is the only package i can't include in the composer.json with a specific version.

Provide global switch

There are scenarios where memcache will be unavailable, or you want to disable it for testing purposes. It would be good to have a flag to turn it off globally, but still allow the following code to run:

$items = $app['memcache']->get('saleitems:'.$sale['id'], function() use ($app, $sale) {
    return $app['db']->fetchAll("SELECT * FROM item WHERE sale_id = ?", array($sale['id']));
});

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.