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

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

phy/cache-bundle
================

Cache Bundle for Symfony2 that supports APC, Memcache, Memcached, Redis, Local, and Disk storage.

1.0.0(11y ago)78.5k1PHPPHP &gt;=5.3.0

Since Sep 21Pushed 1y ago3 watchersCompare

[ Source](https://github.com/mullanaphy/cache-bundle)[ Packagist](https://packagist.org/packages/phy/cache-bundle)[ RSS](/packages/phy-cache-bundle/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (16)Used By (0)

PHY/CacheBundle - Simple Symfony2 wrapper around the more common caches.
========================================================================

[](#phycachebundle---simple-symfony2-wrapper-around-the-more-common-caches)

Simple enough to use cache wrapper for Symfony2. Right now supports APC, Local Disk, Memcache, and Memcached.

Install
-------

[](#install)

To include this along with your Symfony2 project then you can just include this in your composer config:

```
"require": {
    "phy/cache-bundle": "1.0.0"
}

```

And update composer accordingly.

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

[](#configuration)

Here's an example of our services.yml, you don't really need to change this since values come from parameters.yml

```
services:
  phy_cache.client:
    class: '%phy_cache.class%'
    arguments: [ '%phy_cache.settings%' ]
  phy_cache:
    class: PHY\CacheBundle\Cache
    arguments: [ '@phy_cache.client' ]
    calls:
      - [ setExpiration, [ '%phy_cache.expiration%' ] ]
      - [ setCompression, [ '%phy_cache.compression%' ] ]
      - [ setPrefix, [ '%phy_cache.prefix%' ] ]
```

Here's how you'd setup some common caches in your parameters.yml

Memcache

```
parameters:
    phy_cache.class: PHY\CacheBundle\Cache\Memcache
    phy_cache.settings:
      server: [ 127.0.0.1:11211 ]
    phy_cache.prefix: phy_
    phy_cache.expiration: 300
    phy_cache.compression: 0
```

Disk

```
parameters:
    phy_cache.class: PHY\CacheBundle\Cache\Disk
    phy_cache.settings:
      location: /var/tmp/cache/
    phy_cache.expiration: 300
    phy_cache.compression: 0
```

Apc

```
parameters:
    phy_cache.class: PHY\CacheBundle\Cache\Apc
    phy_cache.settings:
      mode: opcode
    phy_cache.prefix: phy_
    phy_cache.expiration: 300
    phy_cache.compression: 0
```

Redis

```
parameters:
    phy_cache.class: PHY\CacheBundle\Cache\Redis
    phy_cache.settings:
      server: 127.0.0.1
      port: 6379
      password: pants
    phy_cache.prefix: phy_
    phy_cache.expiration: 300
    phy_cache.compression: 0
```

Usage
-----

[](#usage)

To call the cache inside your controller (or any container aware class) you just need to call it by its service name.

```
$cache = $this->container->get('phy_cache');
```

From there, you can start setting, getting, replacing, incrementing, decrementing, and so forth.

```
$id = 1;
$cache = $this->container->get('phy_cache');
$hashKey = 'someModel/'.$id;

if(!$someModel = $cache->get($hashKey)) {
    $someModel = $this->loadModel($id);
    $cache->set($hashKey, $someModel, 300);
    $cache->increment($hashKey.'/loads', 1);
}
```

All methods available are almost 100% equal to [\\Memcache](php.net/manual/en/class.memcache.php).

Command Line
------------

[](#command-line)

There are several command line options to handle simple cache methods. All commands have an ability to overwrite the cache used with the --config option. If --config isn't set it will use the generic phy\_cache otherwise you can pass along a config in a JSON string in this format:

```
{
  "type": "disk",
  "client": {
    "location": "./tmp"
  },
  "options": {
    "prefix": "phy_",
    "expiration": 300,
    "compression": 0
  }
}
```

Check current running stats (Needs some style and extra functionality)

```
php app/console phy:cache:stats

```

And flushing your cache completely

```
php app/console phy:cache:flush

```

Set something

```
php app/console phy:cache:set --key something --value 3 --compress 0 --expires 40

```

Replace something

```
php app/console phy:cache:replace --key something --value 3 --compress 0 --expires 40

```

Get something

```
php app/console phy:cache:get --key something --compress 0

```

Delete something

```
php app/console phy:cache:delete --key something

```

Decrement something

```
php app/console phy:cache:decrement --key something --value 3

```

About
-----

[](#about)

Originally was using [BerylliumCacheBundle](https://github.com/beryllium/CacheBundle) by [Kevin Boyd](https://github.com/beryllium). Got the job done for the most part but I needed to compress some rather large aggregate results from MongoDB. Made a pull request to add the compression on and noticed certain other functions weren't quite implemented yet. Having already done a similar bundle for Cache (albeit not for Symfony2) figured I could just port that over and here we are.

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

[](#requirements)

- PHP 5.3+

Testing
-------

[](#testing)

Tests will try and use all the different cache clients and if they aren't installed, or cannot connect to the desired cache file then those tests will be skipped. To test Disk caching, there needs to be a tmp directory that is writable which will be cleaner before and after a test run. To run all you need to do in the command line is:

```
phpunit

```

Submitting bugs and feature requests
------------------------------------

[](#submitting-bugs-and-feature-requests)

Please send bugs to me via [GitHub](https://github.com/mullanaphy/CacheBundle/issues)

Author
------

[](#author)

John Mullanaphy -  - That's it for now...

License
-------

[](#license)

PHY/CacheBundle is licensed under the Open Software License (OSL 3.0) - see the `LICENSE` file for details

Acknowledgements
----------------

[](#acknowledgements)

- [Kevin Boyd](https://github.com/beryllium)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

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 ~35 days

Recently: every ~0 days

Total

15

Last Release

4126d ago

Major Versions

0.1.3 → 1.0.02015-01-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/205741c60b0ce9f5aa1355ea18d171f4ac821047d763e4fe6821e56f8e6f3203?d=identicon)[mullanaphy](/maintainers/mullanaphy)

---

Top Contributors

[![mullanaphy](https://avatars.githubusercontent.com/u/699498?v=4)](https://github.com/mullanaphy "mullanaphy (30 commits)")

---

Tags

symfonyrediscachememcachedapcmemcachedisk

### Embed Badge

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

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

###  Alternatives

[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

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

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[ihor/cachalot

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

2528.1k](/packages/ihor-cachalot)[robinn/phpcacheadmin

A web dashboard for your favorite caching system.

4441.1k1](/packages/robinn-phpcacheadmin)

PHPackages © 2026

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