PHPackages                             naroga/stash-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. naroga/stash-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

naroga/stash-bundle
===================

Incorporates the Stash caching library into Symfony.

0.7.1(6y ago)020BSD-3-ClausePHPPHP ^7.0

Since Nov 25Pushed 6y agoCompare

[ Source](https://github.com/naroga/TedivmStashBundle)[ Packagist](https://packagist.org/packages/naroga/stash-bundle)[ Docs](http://github.com/tedious/TedivmStashBundle)[ RSS](/packages/naroga-stash-bundle/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (9)Versions (19)Used By (0)

TedivmStashBundle [![Build Status](https://camo.githubusercontent.com/1c45ad6c078e3f77da8ff5a0dbcd2aaf6b524900baf0bd5c7114f7c783220297/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f746564696f75732f54656469766d537461736842756e646c652e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/tedious/TedivmStashBundle)
=========================================================================================================================================================================================================================================================================================================================================

[](#tedivmstashbundle-)

[![License](https://camo.githubusercontent.com/52580c4e48510980539cb5b1da14a563b7374da51d773c16d21714d3a6e539cc/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74656469766d2f73746173682d62756e646c652e737667)](https://github.com/tedious/TedivmStashBundle/blob/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/cc696a9501a79e24a8ea28a7591459ab70d396734a7f9ca692c51c4083bd2b9f/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f746564696f75732f54656469766d537461736842756e646c652e737667)](https://packagist.org/packages/tedivm/stash-bundle)[![Coverage Status](https://camo.githubusercontent.com/a1e992fce1c3ea5dc867520624c60bfea200d3d023acc0b2219a8ffb2831e37b/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f746564696f75732f54656469766d537461736842756e646c652e737667)](https://coveralls.io/r/tedious/TedivmStashBundle?branch=master)[![Total Downloads](https://camo.githubusercontent.com/4318c3af9a2b3eb714ec62c351b0bdb47cabc86608cdcee69f35b6e811fd46f1/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74656469766d2f73746173682d62756e646c652e737667)](https://packagist.org/packages/tedivm/stash-bundle)

The **TedivmStashBundle** integrates the [Stash caching library](https://github.com/tedious/Stash) 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.

Both the bundle and Stash are licensed under the New BSD License. Please fork us on [Github](https://github.com/tedious/TedivmStashBundle)!

Installation
------------

[](#installation)

Add the bundle using composer, either by requiring it on the command line:

```
composer require tedivm/stash-bundle
```

or by adding it directly to your `composer.json` file:

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

Add the bundle to `app/AppKernel.php`:

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

And then set the basic configuration in `app/config/config.yml`:

```
stash: ~
```

Usage
-----

[](#usage)

Just fetch the default cache pool service:

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

Or a custom-defined cache pool:

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

Then you can use the cache service directly:

```
$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](http://stash.tedivm.com/) for more information on using the cache service.)

Configuration
-------------

[](#configuration)

### Default Cache Service

[](#default-cache-service)

To get started quickly, you can define a single caching service with a single driver:

```
stash:
    drivers: [ FileSystem ]
    FileSystem: ~
```

This cache service will be registered as `stash.default_cache`, which will also be automatically aliased to `cache`.

### Configuring Drivers

[](#configuring-drivers)

You can set the individual parameters of the cache driver directly in the configuration:

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

### Multiple Drivers

[](#multiple-drivers)

If you want to use multiple drivers in sequence, you can list them separately:

```
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.)

### In-Memory

[](#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:

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

### Doctrine Adapter

[](#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:

```
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:

```
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

[](#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:

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

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

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

### Logger

[](#logger)

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

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

### Multiple Services

[](#multiple-services)

You can also configure multiple services, each of which stores is entirely separate:

```
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.

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

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

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

### Tracking

[](#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:

```
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
--------------------------

[](#stash-driver-configuration)

Each driver comes with a set of default options which can be individually overridden.

```
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:
Memcache:
    servers:
        - { server: 127.0.0.1, port: 11211, weight: 1 }
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~165 days

Recently: every ~379 days

Total

17

Last Release

2274d ago

PHP version history (3 changes)v0.1.2PHP &gt;=5.3.0

v0.5.3PHP ^5.4|^7.0

v0.7.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/67a9373bd6218e10eaa1941dd01ec5ea1299d4534870e5c88722ec978f658f9d?d=identicon)[naroga](/maintainers/naroga)

---

Top Contributors

[![tedivm](https://avatars.githubusercontent.com/u/121709?v=4)](https://github.com/tedivm "tedivm (176 commits)")[![jhallbachner](https://avatars.githubusercontent.com/u/910695?v=4)](https://github.com/jhallbachner "jhallbachner (41 commits)")[![digibeuk](https://avatars.githubusercontent.com/u/5148394?v=4)](https://github.com/digibeuk "digibeuk (7 commits)")[![andrerom](https://avatars.githubusercontent.com/u/289757?v=4)](https://github.com/andrerom "andrerom (6 commits)")[![layanto](https://avatars.githubusercontent.com/u/245078?v=4)](https://github.com/layanto "layanto (6 commits)")[![samarties](https://avatars.githubusercontent.com/u/3956871?v=4)](https://github.com/samarties "samarties (5 commits)")[![lolautruche](https://avatars.githubusercontent.com/u/313528?v=4)](https://github.com/lolautruche "lolautruche (3 commits)")[![kwojc](https://avatars.githubusercontent.com/u/5415799?v=4)](https://github.com/kwojc "kwojc (3 commits)")[![andheiberg](https://avatars.githubusercontent.com/u/820962?v=4)](https://github.com/andheiberg "andheiberg (2 commits)")[![eddiejaoude](https://avatars.githubusercontent.com/u/624760?v=4)](https://github.com/eddiejaoude "eddiejaoude (2 commits)")[![jhallbachner-mb](https://avatars.githubusercontent.com/u/753577?v=4)](https://github.com/jhallbachner-mb "jhallbachner-mb (2 commits)")[![jonny-no1](https://avatars.githubusercontent.com/u/282458?v=4)](https://github.com/jonny-no1 "jonny-no1 (2 commits)")[![naroga](https://avatars.githubusercontent.com/u/3511149?v=4)](https://github.com/naroga "naroga (2 commits)")[![Zeichen32](https://avatars.githubusercontent.com/u/1432899?v=4)](https://github.com/Zeichen32 "Zeichen32 (1 commits)")[![fred-jan](https://avatars.githubusercontent.com/u/2146611?v=4)](https://github.com/fred-jan "fred-jan (1 commits)")[![emgiezet](https://avatars.githubusercontent.com/u/1410665?v=4)](https://github.com/emgiezet "emgiezet (1 commits)")[![crevillo](https://avatars.githubusercontent.com/u/306215?v=4)](https://github.com/crevillo "crevillo (1 commits)")[![Lumbendil](https://avatars.githubusercontent.com/u/184785?v=4)](https://github.com/Lumbendil "Lumbendil (1 commits)")[![magnusnordlander](https://avatars.githubusercontent.com/u/165002?v=4)](https://github.com/magnusnordlander "magnusnordlander (1 commits)")[![mattattui](https://avatars.githubusercontent.com/u/93214?v=4)](https://github.com/mattattui "mattattui (1 commits)")

---

Tags

symfonyrediscachecachingmemcachedapcsessionsstash

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/naroga-stash-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/naroga-stash-bundle/health.svg)](https://phpackages.com/packages/naroga-stash-bundle)
```

###  Alternatives

[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[jamm/memory

Key-value storage in memory. As a storage can be used: APC, Redis, Memcache, Shared memory. All storage objects have one interface, so you can switch them without changing the working code. Contains PHP Redis client.

13326.3k1](/packages/jamm-memory)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
