2017 © Pedro Peláez
 

symfony-bundle stash-bundle

Incorporates the Stash caching library into Symfony.

image

tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

  • Tuesday, February 28, 2017
  • by tedivm
  • Repository
  • 7 Watchers
  • 84 Stars
  • 722,849 Installations
  • PHP
  • 25 Dependents
  • 0 Suggesters
  • 39 Forks
  • 17 Open issues
  • 17 Versions
  • 5 % Grown

The README.md

TedivmStashBundle Build Status

License Latest Stable Version Coverage Status Total Downloads, (*1)

The TedivmStashBundle integrates the Stash caching library into Symfony, providing a powerful abstraction for a range of caching engines. This bundle provides a caching service, adds Stash information to the Web Profiler toolbar, and adds integration for the Doctrine Common Cache library., (*2)

Both the bundle and Stash are licensed under the New BSD License. Please fork us on Github!, (*3)

Installation

Add the bundle using composer, either by requiring it on the command line:, (*4)

composer require tedivm/stash-bundle

or by adding it directly to your composer.json file:, (*5)

"require": {
    "tedivm/stash-bundle": "0.7.*"
}

Add the bundle to app/AppKernel.php:, (*6)

public function registerBundles()
{
    return array(
        new Tedivm\StashBundle\TedivmStashBundle(),
    );
}

And then set the basic configuration in app/config/config.yml:, (*7)

stash: ~

Usage

Just fetch the default cache pool service:, (*8)

$pool = $this->container->get('stash');

Or a custom-defined cache pool:, (*9)

$pool = $this->container->get('stash.custom_cache');

Then you can use the cache service directly:, (*10)

$item = $pool->getItem($id, 'info'); // cache keys, more than one can be used

$info = $item->get();

if($item->isMiss())
{
    $info = loadInfo($id);
    $item->set($userInfo, 60); // second parameter is TTL (in seconds or future \Datetime object)
}

return $info;

(See the Stash documentation for more information on using the cache service.), (*11)

Configuration

Default Cache Service

To get started quickly, you can define a single caching service with a single driver:, (*12)

stash:
    drivers: [ FileSystem ]
    FileSystem: ~

This cache service will be registered as stash.default_cache, which will also be automatically aliased to cache., (*13)

Configuring Drivers

You can set the individual parameters of the cache driver directly in the configuration:, (*14)

stash:
    drivers: [ FileSystem ]
    FileSystem:
        dirSplit: 3
        path: /tmp

Multiple Drivers

If you want to use multiple drivers in sequence, you can list them separately:, (*15)

stash:
    drivers: [ Apc, FileSystem ]
    Apc: ~
    FileSystem:
        path: /tmp

The cache service will automatically be configured with a Composite driver, with the drivers queried in the specified order (for example, in this example, Apc would be queried first, followed by FileSystem if that query failed.), (*16)

In-Memory

By default, every cache service includes in-memory caching: during the lifetime of a single request, any values stored or retrieved from the cache service will be stored in memory, with the in-memory representation being checked before any other drivers. In some circumstances, however (such as long-running CLI batch scripts) this may not be desirable. In those cases, the in-memory driver can be disabled:, (*17)

stash:
    drivers: [ Apc ]
    inMemory: false
    Apc: ~

Doctrine Adapter

Stash provides a Doctrine cache adapter so that your Stash caching service can be injected into any service that takes a DoctrineCacheInterface object. To turn on the adapter for a service, set the parameter:, (*18)

stash:
    drivers: [ Apc ]
    registerDoctrineAdapter: true
    Apc: ~

For the default cache, the Adapter service will be added to the container under the name stash.adapter.doctrine.default_cache. You can use it anywhere you'd use a regular Doctrine Cache object:, (*19)

doctrine:
    orm:
        metadata_cache_driver:
            type: service
            id: stash.adapter.doctrine.default_cache
        query_cache_driver:
            type: service
            id: stash.adapter.doctrine.default_cache
        result_cache_driver:
            type: service
            id: stash.adapter.doctrine.default_cache

Session Adapter

Stash provides a session adapter to allow Symfony sessions to be stored directly inside the cache. To turn on the adapter, set the parameter:, (*20)

stash:
    drivers: [ Apc ]
    registerSessionHandler: true
    Apc: ~

Once it's enabled, enable it in the framework bundle and it will automatically be used:, (*21)

framework:
    session:
        handler_id: stash.adapter.session.default_cache

Logger

Stash supports PSR Compliant logging libraries, you can specify which library is used by passing the logger's service name as a parameter:, (*22)

stash:
    drivers: [ FileSystem ]
    logger: logger
    FileSystem: ~ 

Multiple Services

You can also configure multiple services, each of which stores is entirely separate:, (*23)

stash:
    caches:
        first:
            drivers: [ FileSystem ]
            registerDoctrineAdapter: true
            FileSystem: ~
        second:
            drivers: [ Apc, FileSystem ]
            inMemory: false
            logger: logger
            FileSystem: ~

Each service is defined with keys inside a separate, distinct internal namespace, so you can use multiple services to avoid key collisions between distinct services even if you only have a single backend available., (*24)

When multiple caches are defined, you can manually define a default, which will be aliased to the stash service:, (*25)

stash:
    default_cache: first
    first:
        ...
    second:
        ...

If you don't, the first service defined will be set as the default., (*26)

Tracking

StashBundle includes a module which tracks the keys of all cache queries made during a request for debugging purposes. By default this module is enabled in the dev and test environments but disabled elsewhere. However, if you want to override the default behavior, you can enable or disable this behavior in the configuration:, (*27)

stash:
    tracking: true # enables query logging, false to disable
    tracking_values: true # enables query logging of full cache values, false to disable

Stash Driver Configuration

Each driver comes with a set of default options which can be individually overridden., (*28)

FileSystem:
    dirSplit:               2
    encoder:                Native
    path:                   %kernel.cache_dir%/stash
    filePermissions:        0660
    dirPermissions:         0770
    memKeyLimit:            20
SQLite:
    path:                   %kernel.cache_dir%/stash
    filePermissions:        0660
    dirPermissions:         0770
    busyTimeout:            500
    nesting:                0
    subdriver:              PDO
Apc:
    ttl:                    300
    namespace:              <none>
Memcache:
    servers:
        - { server: 127.0.0.1, port: 11211, weight: 1 }

The Versions

28/02 2017

dev-master

9999999-dev http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

28/02 2017

v0.6.2

0.6.2.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

11/02 2016

v0.6.1

0.6.1.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

29/12 2015

v0.5.3

0.5.3.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

29/12 2015

dev-updated_dev_dependecies

dev-updated_dev_dependecies http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

19/11 2015

v0.5.2

0.5.2.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

19/11 2015

v0.4.3

0.4.3.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

02/08 2015

v0.5.1

0.5.1.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

08/12 2014

v0.4.2

0.4.2.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

05/06 2014

v0.4.1

0.4.1.0 http://github.com/tedious/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Robert Hafner

cache redis apc caching memcached symfony sessions stash

23/01 2014

v0.2.4

0.2.4.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

22/01 2014

v0.3.2

0.3.2.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

08/01 2014

v0.3.1

0.3.1.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

31/07 2013

v0.2.3

0.2.3.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

26/06 2013

v0.2.2

0.2.2.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

17/06 2013

v0.2.1

0.2.1.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions

25/11 2012

v0.1.2

0.1.2.0 http://github.com/tedivm/TedivmStashBundle

Incorporates the Stash caching library into Symfony.

  Sources   Download

BSD-3-Clause

The Requires

 

by Robert Hafner

caching symfony sessions