2017 © Pedro Peláez
 

library cache-service-provider

A Cache Service Provider for Silex 2.0, using the doctrine/cache package

image

euskadi31/cache-service-provider

A Cache Service Provider for Silex 2.0, using the doctrine/cache package

  • Wednesday, June 17, 2015
  • by euskadi31
  • Repository
  • 1 Watchers
  • 0 Stars
  • 422 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Silex Cache Service Provider

Build Status SensioLabsInsight, (*1)

This service provider for Silex 2.0 uses the Cache classes from Doctrine Common to provide a cache service to a Silex application, and other service providers., (*2)

Install

Add euskadi31/cache-service-provider to your composer.json:, (*3)

% php composer.phar require euskadi31/cache-service-provider:~1.0

Usage

Configuration

If you only need one application wide cache, then it's sufficient to only define a default cache, by setting the default key in cache.options., (*4)

The cache definition is an array of options, with driver being the only mandatory option. All other options in the array, are treated as constructor arguments to the driver class., (*5)

The cache named default is the cache available through the app's cache service., (*6)

<?php

$app = new Silex\Application;

$app->register(new \Euskadi31\Silex\Provider\CacheServiceProvider, [
    'cache.options' => [
        'default' => [
            'driver' => 'apc'
        ]
    ]
]);

The driver name can be either:, (*7)

  • A fully qualified class name
  • A simple identifier like "apc", which then gets translated to \Doctrine\Common\Cache\ApcCache.
  • A Closure, which returns an object implementing \Doctrine\Common\Cache\Cache.

This cache is then available through the cache service, and provides an instance of Doctrine\Common\Cache\Cache:, (*8)

if ($app['cache']->contains('foo')) {
    echo $app['cache']->fetch('foo'), "<br />";
} else {
    $app['cache']->save('foo', 'bar');
}

To configure multiple caches, define them as additional keys in cache.options:, (*9)

$app->register(new \Euskadi31\Silex\Provider\CacheServiceProvider, [
    'cache.options' => [
        'default' => [
            'driver' => 'apc'
        ],
        'file' => [
            'driver' => 'filesystem',
            'directory' => '/tmp/myapp'
        ],
        'global' => [
            'driver' => function() {
                $redis = new \Doctrine\Common\Cache\RedisCache;

                $redis->setRedis($app['redis']);

                return $redis;
            }
        ]
    ]
]);

All caches (including the default) are then available via the caches service:, (*10)

$app['caches']['file']->save('foo', 'bar');

License

CacheServiceProvider is licensed under the MIT license., (*11)

The Versions

17/06 2015

dev-master

9999999-dev

A Cache Service Provider for Silex 2.0, using the doctrine/cache package

  Sources   Download

MIT

The Requires

 

The Development Requires

17/06 2015

v1.0

1.0.0.0

A Cache Service Provider for Silex 2.0, using the doctrine/cache package

  Sources   Download

MIT

The Requires

 

The Development Requires