PHPackages                             m1/stash-silex - 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. m1/stash-silex

ActiveLibrary[Caching](/categories/caching)

m1/stash-silex
==============

StashSilex is a Silex service provider and session handler for the popular caching library Stash

1.0.0(9y ago)53.2k2MITPHPPHP &gt;=5.3.0

Since Jan 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/m1/StashSilex)[ Packagist](https://packagist.org/packages/m1/stash-silex)[ Docs](https://github.com/M1/StashSilex)[ RSS](/packages/m1-stash-silex/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

StashSilex
==========

[](#stashsilex)

[![Author](https://camo.githubusercontent.com/ed167a3f87bb811a7e157913a2461cc647ef51ca73a97b674a7805f54b8caa70/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406d696c657363726f78666f72642d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/milescroxford)[![Latest Version on Packagist](https://camo.githubusercontent.com/aac0229f035501c5e832f9d476cf62757506b7f490da9ce75098cf2862d6511b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d312f73746173682d73696c65782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/m1/stash-silex)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6fb1d99e4ea4de9095110c69891c0be16105efe3665d496068b350c06e541093/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d312f537461736853696c65782f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/m1/StashSilex)[![Coverage Status](https://camo.githubusercontent.com/715c0ac73b8b5be25796ac24de2ffdbad9e0ef2c4ad6623b54cf29bb061959c5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f4d312f537461736853696c65782e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/M1/StashSilex/code-structure)[![Quality Score](https://camo.githubusercontent.com/2384eeb6ff4dca65ddaceb95079f3facd68ea0337739fd69dfd0d53fe361f019/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4d312f537461736853696c65782e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/M1/StashSilex)

StashSilex is a [Silex](http://silex.sensiolabs.org/) service provider and session handler for the popular caching library [Stash](http://www.stashphp.com/index.html).

Requirements
------------

[](#requirements)

StashSilex requires PHP version `5.3+`, Silex version `1.*` and Stash version `0.11+`

Install
-------

[](#install)

Via Composer

```
$ composer require M1/StashSilex
```

Usage
-----

[](#usage)

You use the StashServiceProvider to register the service provider with the usual syntax for registering service providers:

```
$app->register(new M1\StashSilex\StashServiceProvider());
```

There's a few options you can use when registering the service provider.

### Pools

[](#pools)

You can register either one pool using `pool.options` or multiple using `pools.options`, this works like the [Doctrine Service Provider](http://silex.sensiolabs.org/doc/providers/doctrine.html).

Registering one pool:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
    )
));

$item = $app['pool']->getItem('path/to/item');
```

Registering multiple pools:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pools.options' => array(
        'fs' => array(
            'driver' => 'FileSystem',
            'options' => array(
                'path' => __DIR__.'/../../app/cache',
            ),
        ),
        'mc' => array(
            'driver' => 'Memcache',
            'options' => array(
                'servers' => array(
                    '127.0.0.1', '11211'
                )
            ),
        ),
    ),
));

// same thing
$item1 = $app['pools']['fs']->getItem('path/to/item');
$item1 = $app['pool']->getItem('path/to/item');

$item2 = $app['pools']['mc']->getItem('path/to/item');
```

You can access your pools through `$app['pool']` and `$app['pools']['the_key_of_your_pool']`. If you have multiple pools, then your first pool registered will be available through `$app['pool']`.

For example, in the above code, the `FileSystem` pool will be available through `$app['pool']` and `$app['pools']['fs']`.

### Drivers

[](#drivers)

The driver option is based on the class names for the available drivers, [see here](http://www.stashphp.com/Drivers.html)for the class names defined by Stash. The driver names are case sensitive.

You can set the driver options through `options` like so:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
    )
));
```

You can see the full list of the available options for each driver [here](http://www.stashphp.com/Drivers.html). The default driver if no driver is defined is the `Ephemeral` driver.

### Logger

[](#logger)

You can also set the logger for the pool via the `logger` option like so:

```
$app->register(new Silex\Provider\MonologServiceProvider(), array(
    'monolog.logfile' => __DIR__.'/../../app/logs/app/dev.log',
));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'logger' => 'monolog'
    )
));
```

The logger is `monolog` due to the `MonologServiceProvider` populating `$app['monolog']`. The logger option is a string which your logger service can be accessed through `$app`.

For example if you decided to not use `Monolog` through the service provider (not recommended), you can use your custom logger like so:

```
$app['mylog'] = $app->share(function($app) {
    $logger = new \Monolog\Logger('mylog');
    $logger->pushHandler(new Monolog\Handler\StreamHandler('/logfile/mylog.log', Logger::INFO));
    return $logger;
});

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'logger' => 'mylog'
    )
));
```

### Sessions

[](#sessions)

You can choose to handle your sessions through Stash in a couple of different ways.

The first way is via the service provider.

The below creates sessions with defaults:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'session' => true
    )
));
```

You can also set the `ttl` and the `session prefix` (what namespace it is stored in in stash, more info [here](http://www.stashphp.com/Grouping.html)) like so:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'session' => array(
            'prefix' => 'session_name',
            'expiretime' => 3200
        )
    )
));
```

You can also set the `SessionHandler` manually via:

```
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        )
    )
));

// Without options
$app['session.storage.handler'] = $app->share(function ($app) {
    return new M1\StashSilex\StashSessionHandler($app['pool']);
});

// With options
$app['session.storage.handler'] = $app->share(function ($app) {
    return new M1\StashSilex\StashSessionHandler($app['pool'], array(
        'prefix' => 'session_name',
        'expiretime' => 3200
    ));
});
```

### Recommendations

[](#recommendations)

Instead of setting the options through an array, think about using a config loader like [`m1/vars`](https://github.com/m1/vars), where you can just load the configuration of your pool(s) via a file like so:

```
# example.yml
pools:
    filesystem:
        driver: FileSystem
        options:
            path: %dir%/../../app/cache
        session:
            prefix: session_name
            expiretime: 3200
```

```
$app->register(new M1\Vars\Provider\Silex\VarsServiceProvider('example.yml'), array(
    'vars.options' => array(
        'variables' => array(
            'dir' => __DIR__
        ),
)));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pools.options' => $app['vars']['pools']
));
```

This way makes it so much easier to make small little changes without having to dive into code.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Miles Croxford](https://github.com/m1)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~112 days

Total

3

Last Release

3547d ago

Major Versions

0.2.0 → 1.0.02016-08-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/60c0a2476209607aae2ba8d4c99b094baa1e482740622cd19c9ef6bb86b0ba47?d=identicon)[m1](/maintainers/m1)

---

Top Contributors

[![m1](https://avatars.githubusercontent.com/u/978089?v=4)](https://github.com/m1 "m1 (16 commits)")

---

Tags

rediscachecachingserviceproviderhandlermemcachedsessionextensionapcsessionssilexm1stashserviceproviderstashsilexstash-silexsessionhandler

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/m1-stash-silex/health.svg)

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

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

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[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)
