PHPackages                             slm/cache - 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. slm/cache

ActiveLibrary[Caching](/categories/caching)

slm/cache
=========

Zend Framework 2 module to enable route based page caching

v0.1.0(12y ago)12598[1 issues](https://github.com/juriansluiman/SlmCache/issues)[2 PRs](https://github.com/juriansluiman/SlmCache/pulls)BSD-3-ClausePHPPHP &gt;=5.3.3.

Since Dec 5Pushed 12y ago1 watchersCompare

[ Source](https://github.com/juriansluiman/SlmCache)[ Packagist](https://packagist.org/packages/slm/cache)[ Docs](https://github.com/juriansluiman/SlmCache)[ RSS](/packages/slm-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

SlmCache
========

[](#slmcache)

[![Build Status](https://camo.githubusercontent.com/d126267e6ee8315f476a1c67371635994c75b137a61729bfd57ecc73944e2070/68747470733a2f2f7472617669732d63692e6f72672f6a757269616e736c75696d616e2f536c6d43616368652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/juriansluiman/SlmCache)[![Latest Stable Version](https://camo.githubusercontent.com/d7dd9c4f6d3b546b5174fa4649b50524a0313114b4d4e2ba79bef45bebb2f5a8/68747470733a2f2f706f7365722e707567782e6f72672f736c6d2f63616368652f762f737461626c652e706e67)](https://packagist.org/packages/slm/cache)

Version 0.1.0 Created by Jurian Sluiman

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

[](#requirements)

- [Zend Framework 2](https://github.com/zendframework/zf2)

Introduction
------------

[](#introduction)

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

[](#installation)

SlmCache works with Composer. To install it, just add the following line into your `composer.json` file:

```
"require": {
    "slm/cache": "~0.1"
}
```

Documentation
-------------

[](#documentation)

SlmCache works with a configured cache storage adapter and a list of routes which can be cached. Based on the request and the matched route SlmCache will fetch the response from the cache or not.

### Configure cache storage

[](#configure-cache-storage)

The cache can be configured in two ways. The first method uses the cache storage factory to instantiate a new cache instance. The second method let you point to a service in the service locator to fetch an existing cache service.

In below example, all configuration inside `cache` will be injected into the `Zend\Cache\StorageFactory::factory()` method. This enables you to configure the adapter, all adapter options and if needed, plugins.

```
'slm_cache' => array(
    'cache'  => array(
        'adapter' => array(
            'name'    => 'apc',
            'options' => array('ttl' => 3600),
        ),
    ),
),
```

In this example, the configuration is simply a string and points to a service. This enables you to have a single cache service in your application which can be used for other things than only SlmCache.

```
'slm_cache' => array(
    'cache'  => 'my-cache-adapter'
),
```

### Configure cache prefix

[](#configure-cache-prefix)

Cache prefix is used to namespace cached data so it will not conflict with other modules. Ideally it should be unique.

```
'slm_cache' => array(
    'cache_prefix' => 'my_cache_prefix_',
);
```

In case you don't specify a cache\_prefix, SlmCache will default to 'slm\_cache\_'.

### Configure routes to be cached

[](#configure-routes-to-be-cached)

The routes which can be cached must be configured in a single array. SlmCache will match the currently matched route name to this list of routes. If there is a match, the caching mechanism will be enabled. This allows you to have non-cached and cached routes inside a single application.

If the SlmCache is triggered, the cache will be used to fetch the response body. With short-circuiting the event system of Zend Framework 2, this result is directly returned to the browser. This will bypass the complete `EVENT_DISPATCH` part of the application execution. If there is no hit on the cache, SlmCache will wait until the application has finished rendering the complete response. This response is stored in the cache so next time a request takes place, the cache has a hit.

To configure a route to be cached, set it inside the `routes` array:

```
'slm_cache' => array(
    'routes'  => array(
        'home'  => array(),
        'about' => array(),
    ),
),
```

### Match only routes for some HTTP methods

[](#match-only-routes-for-some-http-methods)

There is the possibility you have a route which is used for both GET and POST. You can configure SlmCache to only keep a cached version of the GET version and not cache the POST. Use the array to set the `match_method`:

```
'slm_cache' => array(
    'routes'  => array(
        'contact' => array('match_method' => 'GET'),
    ),
),
```

You can also match multiple methods, if you need to:

```
'slm_cache' => array(
    'routes'  => array(
        'contact' => array('match_method' => 'GET', 'HEAD'),
    ),
),
```

### Match only routes with specified route parameters

[](#match-only-routes-with-specified-route-parameters)

If you have a segment route where a part in the route sets the action, you might want to only cache a specific action. For the route `foo[/:action]` you might want to cache the match where `action` is `bar` but not for the `action` equals to `baz`. Use the `match_route_params` flag to configure this filtering:

```
'slm_cache' => array(
    'routes'  => array(
        'foo' => array(
            'match_route_params' => array('action' => 'bar')
        ),
    ),
),
```

You can have multiple actions you allow, but not all. The value can be an array of possible actions:

```
'slm_cache' => array(
    'routes'  => array(
        'foo' => array(
            'match_route_params' => array('action' => array('bar', 'baz'))
        ),
    ),
),
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

Unknown

Total

1

Last Release

4539d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c8ca0c8435ae4c01c201bb52f63a72a8f9ef203f61535d7daf588f6b3a7df1c?d=identicon)[juriansluiman](/maintainers/juriansluiman)

---

Top Contributors

[![marcelo-lipienski](https://avatars.githubusercontent.com/u/691173?v=4)](https://github.com/marcelo-lipienski "marcelo-lipienski (4 commits)")[![Repkit](https://avatars.githubusercontent.com/u/2531428?v=4)](https://github.com/Repkit "Repkit (1 commits)")

---

Tags

cachezf2route

### Embed Badge

![Health badge](/badges/slm-cache/health.svg)

```
[![Health](https://phpackages.com/badges/slm-cache/health.svg)](https://phpackages.com/packages/slm-cache)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[psr/cache

Common interface for caching libraries

5.2k686.9M1.3k](/packages/psr-cache)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[maartenstaa/laravel-41-route-caching

This package allows you to cache your routes definitions, thereby speeding up each request.

25371.9k](/packages/maartenstaa-laravel-41-route-caching)[stroker/cache

Provides a full page cache solution for Laminas

6444.7k](/packages/stroker-cache)[beste/in-memory-cache

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

2512.2M6](/packages/beste-in-memory-cache)

PHPackages © 2026

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