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

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

epiphany/service-cache-bundle
=============================

Cache or store responses from a Symfony2 service by annotating its methods

1.0.8(12y ago)0331MITPHPPHP &gt;=5.3.0

Since Sep 23Pushed 12y ago12 watchersCompare

[ Source](https://github.com/epiphanysearch/service-cache-bundle)[ Packagist](https://packagist.org/packages/epiphany/service-cache-bundle)[ RSS](/packages/epiphany-service-cache-bundle/feed)WikiDiscussions master Synced 2mo ago

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

Epiphany Service Cache Bundle
=============================

[](#epiphany-service-cache-bundle)

Allows caching of Symfony2 service method calls. This is achieved by annotating the required methods in the service class.

This functionality may be useful where:

1. An application makes expensive calls to an API which could be cached or shared with another application, reducing overall API calls.
2. An application makes time consuming calls to a service which could be cached for faster performance.
3. As a means to hook into a method call for a service, then capture its parameters and return value.

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

[](#configuration)

This assumes you're working with a Symfony2 (v2.3) application, and using composer for package management.

There are four steps required to use this bundle.

- Add this package to your composer.json file and run a *composer update*, add the package to you AppKernel
- Update your application's *app/autoload.php* file to include a call to ProxyGenerator::registerNamespace(), as below, so the application can load proxy classes

```
use Epiphany\ServiceCacheBundle\Proxy\ProxyGenerator;

....

ProxyGenerator::registerNamespace($loader,__DIR__);

return $loader;
```

- Tag any services you want to register for caching, and tag a service which implements the *Epiphany\\ServiceCacheBundle\\Cache\\ServiceCacheInterface*. This should be done in your *service.yml/xml* files

```
services:
    # note the 'epiphany_service_cache.register' tag - this indicates our weather data
    # service should have some (or all) of its method calls cached
    weather_data_service:
        class: Epiphany\ServiceCacheDemoBundle\Service\WeatherDataService
        arguments: []
        tags:
            - { name: epiphany_service_cache.register}

    # note the 'epiphany_service_cache.cache' tag - this indicates the service
    # should be used by the service_cache as the caching mechanism
    simple_cache_service:
        class: Epiphany\ServiceCacheDemoBundle\Service\SimpleCacheService
        arguments: [localhost, 12345]
        tags:
            - { name: epiphany_service_cache.cache}
```

- Annotate any services you want to cache..

```
class WeatherDataService
{
    /**
     * Get the weather forecast for a date and location
     *
     * @service-cache-enable
     *
     * @service-cache-key param date
     * @service-cache-key param location
     * @service-cache-key date Y-m-d-H
     *
     * @service-cache-option compressed y
     *
     * @service-cache-expires 0
     *
     * @param  DateTime $date
     * @param  string   $location
     * @return array    forecast data
     */
    public function forecastForDate(\DateTime $date, $location) {

        //....
```

Annotations
-----------

[](#annotations)

`@service-cache-enable` - This marks a method for use with the Service Cache

`@service-cache-key  ` - One or more of these annotations must be used to define a unique key to store any data against. Any method parameter which can be cast as a string, or the current date (with a format string) can be used.

`@service-cache-option  ` - Name/value pairs that will be passed to the caching service during get/set operations via an associative array. See the *Epiphany\\ServiceCacheBundle\\Cache\\ServiceCacheInterface*. This allows a the user to pass extra information that might be specific to their implementation of the cache service such as compression, data expiry, (collection name if you're using MongoDB)

`@service-cache-expires ` - Expiry in seconds of the cached data. Zero for never expires.

Implementing the Cache Mechanism
--------------------------------

[](#implementing-the-cache-mechanism)

It is at the user's discretion as to what means of caching should be used. All that is required is that the user provides a Symfony2 service marked with the *'epiphany\_service\_cache.cache'* tag, which implements the *Epiphany\\ServiceCacheBundle\\Cache\\ServiceCacheInterface*. The getDataForKey() method should return a null value when no data can be retrieved from the cache.

Notes
-----

[](#notes)

This package expects the Symfony2 *logger* service to be available in the container (usually monolog, though any service implementing the *Symfony\\Component\\HttpKernel\\Log\\LoggerInterface* can be used).

To insert the caching layer, this package produces proxy objects for any marked service, and then overrides the service definition in Symfony's pre-optimization compiler pass of the service container. Currently, the proxy objects must be manually deleted from the application's *app/cache/dsproxy* directory whenever their service is updated.

```
class EpiphanyServiceCacheBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        // this pass will override standard service classes with our generated proxy classes
        $container->addCompilerPass(new OverrideServiceCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
    }
}
```

Release Notes
=============

[](#release-notes)

v1.0.2 - September 23 2013
--------------------------

[](#v102---september-23-2013)

- Readme updates.

v1.0.1 - September 23 2013
--------------------------

[](#v101---september-23-2013)

- Readme updates.

v1.0.0 - September 23 2013
--------------------------

[](#v100---september-23-2013)

- Initial Commit, basic functionality.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity62

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

Total

6

Last Release

4614d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1fa633cac4aa69a2a7aca730252b8356e67add7aece6192e3d26de7d83140456?d=identicon)[danmartin-epiphany](/maintainers/danmartin-epiphany)

![](https://www.gravatar.com/avatar/0588d774671af6ec3149f824b01c68dcd5868e2871e9e493a005e974ddb7c8e2?d=identicon)[St0iK](/maintainers/St0iK)

![](https://www.gravatar.com/avatar/c70b18db5484d942674061d20e1b02cce83c11d7398ef893ea3ebcfcee1149df?d=identicon)[steven.lewis@epiphanysolutions.co.uk](/maintainers/steven.lewis@epiphanysolutions.co.uk)

---

Top Contributors

[![steven-lewis](https://avatars.githubusercontent.com/u/3897566?v=4)](https://github.com/steven-lewis "steven-lewis (20 commits)")

---

Tags

containerSymfony2cacheservice

### Embed Badge

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

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

###  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)[moust/silex-cache

Cache service provider for Silex application

33138.4k1](/packages/moust-silex-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)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23817.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

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