PHPackages                             bigpaulie/cachebundle - 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. [Database &amp; ORM](/categories/database)
4. /
5. bigpaulie/cachebundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

bigpaulie/cachebundle
=====================

This bundle provides some extra functionality for multi-domain and ORM caching

v1.1.0(8y ago)1504MITPHPPHP &gt;=5.6

Since May 16Pushed 8y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (4)Used By (0)

CacheBundle [![Build Status](https://camo.githubusercontent.com/b469e16c1f3ce2e2b1b56f437a6273f94bd371abdba14dc49b89485964c75ea6/68747470733a2f2f7472617669732d63692e6f72672f6269677061756c69652f636163686562756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bigpaulie/cachebundle)
==========================================================================================================================================================================================================================================================================================================

[](#cachebundle-)

This bundle provides some extra functionality to the cache layer by exposing a service and a trait in order to make it easier for you to cache your queries.

At the moment this bundle works with Symfony 2.8.x PHP 5.6, PHP 7 and MySQL/MariaDB

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

[](#installation)

The preferred way to install the bundle is via composer

```
composer require bigpaulie/symfony-cachebundle "dev-master" --prefer-dist

```

After requiring the package you should add the bundle to your bundle array in the AppKernel.php

```
$bundles = array(
        ...
        new bigpaulie\CacheBundle\BigpaulieCacheBundle(),
);
```

Import the services.yml in your config.yml at the top of the file

```
- { resource: "@BigpaulieCacheBundle/Resources/config/services.yml"}
```

Add a new parameter in parameters.yml

```
memcached_servers:
        - { host: 127.0.0.1, port: 11211 }
```

Enable/disable caching for specific environments

Place the following in your config\_\*.yml file

```
    bigpaulie_cache:
        enable: true|false
```

Tell doctrine to use a given cache driver

```
doctrine:
    orm:
        metadata_cache_driver:
            type: service
            id: doctrine.cache.driver.memcached
        query_cache_driver:
            type: service
            id: doctrine.cache.driver.memcached
        result_cache_driver:
            type: service
            id: doctrine.cache.driver.memcached
```

Query Caching
-------------

[](#query-caching)

The bundle follows the official API as described in the documentation at [Doctrine Project](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html)

#### DQL Caching

[](#dql-caching)

```
// $qb instanceof QueryBuilder

$qb->select('u')
   ->from('User', 'u')
   ->where('u.id = ?1')
   ->orderBy('u.name', 'ASC')
   ->setParameter(1, 100);

$query = $qb->getQuery();
$query->setQueryCaching(true);

$result = $query->getResult();
```

The setQueryCaching() method supports two additional parameters: lifetime and key.

```
$query->setQueryCaching(true, 3600, 'my_unique_key');
```

#### Entity Caching

[](#entity-caching)

Symfony Framework doesn't support entity caching out of the box, here enters the Cacheable trait. Use the Cacheable trait in the repositories you want to cache.

```
use bigpaulie\CacheBundle\Doctrine\Support\Cacheable;
```

##### Overridden methods:

[](#overridden-methods)

#### find()

[](#find)

```
 find($id, $lifetime = null, \Closure $callable = null)
```

If you specify a lifetime for your cache than the result will be cached.

Additionally there is a third parameter to which you can pass an Closure which will act like a default return in case the query doesn't return any result.

#### findOneBy()

[](#findoneby)

```
findOneBy(array $criteria, array $orderBy = null, $lifetime = null, \Closure $callable = null)
```

If you specify a lifetime for your cache than the result will be cached.

Additionally you can also pass a Closure as the forth parameter which will act as a default return if the query doesn't return any results.

#### findAll()

[](#findall)

```
findAll($lifetime = null, \Closure $callable = null)
```

If you specify a lifetime for your cache than the result will be cached.

Additionally you can also pass a Closure as the second parameter which will act as a default return if the query doesn't return any results.

##### Example Usage

[](#example-usage)

```
use bigpaulie\CacheBundle\Doctrine\Support\Cacheable;
use Doctrine\ORM\EntityRepository;

/**
 * SomeRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class SomeRepository extends EntityRepository
{
    use Cacheable;
}
```

```
// No caching
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1);

// Caching for 3600 seconds
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1, 3600);

// Caching for 3600 seconds and passing a Closure
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1, 3600, function () {
    return new NullObject();
});
```

#### Contribution

[](#contribution)

Feel free to contribute to this project, together we can make it a better project.

Fork, code, submit a pull request or open a issue.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

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

Total

3

Last Release

3270d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1706d209e8e01305b6823045fac6d363e149abd14a4bd20397d237ea1107a2b4?d=identicon)[bigpaulie](/maintainers/bigpaulie)

---

Top Contributors

[![bigpaulie](https://avatars.githubusercontent.com/u/5903753?v=4)](https://github.com/bigpaulie "bigpaulie (10 commits)")

---

Tags

doctrinecachecachingmulti-domain

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bigpaulie-cachebundle/health.svg)

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

###  Alternatives

[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3212.5M32](/packages/matthiasmullie-scrapbook)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[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)[cache/cache-bundle

Symfony 2 bundle providing integration between PSR-6 compliant cache services and the framework. It supports cache for sessions, routing and Doctrine

43437.0k](/packages/cache-cache-bundle)[cache/doctrine-adapter

A PSR-6 cache implementation using Doctrine. This implementation supports tags

151.0M21](/packages/cache-doctrine-adapter)

PHPackages © 2026

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