Skip to content

Updated readme, removed Doctrine cache bundle #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 10 additions & 192 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,212 +1,30 @@
# PHP-Cache cache-bundle
[![Build Status](https://travis-ci.org/php-cache/cache-bundle.png?branch=master)](https://travis-ci.org/php-cache/cache-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/ea12a1b3-09c9-4f0a-9a2c-63d72b47db5a/mini.png)](https://insight.sensiolabs.com/projects/ea12a1b3-09c9-4f0a-9a2c-63d72b47db5a)

#### Cache Bundle for Symfony 2.6 and above
# PSR-6 Cache bundle
[![Latest Stable Version](https://poser.pugx.org/cache/cache-bundle/v/stable)](https://packagist.org/packages/cache/cache-bundle) [![codecov.io](https://codecov.io/github/php-cache/cache-bundle/coverage.svg?branch=master)](https://codecov.io/github/php-cache/cache-bundle?branch=master) [![Build Status](https://travis-ci.org/php-cache/cache-bundle.svg?branch=master)](https://travis-ci.org/php-cache/cache-bundle) [![Total Downloads](https://poser.pugx.org/cache/cache-bundle/downloads)](https://packagist.org/packages/cache/cache-bundle) [![Monthly Downloads](https://poser.pugx.org/cache/cache-bundle/d/monthly.png)](https://packagist.org/packages/cache/cache-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/21963379-2b15-4cc4-bdf6-0f98aa292f8a/mini.png)](https://insight.sensiolabs.com/projects/21963379-2b15-4cc4-bdf6-0f98aa292f8a) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

This is a Symfony bundle that lets you you integrate your PSR-6 compliant cache service with the framework.
It lets you cache your sessions, routes and Doctrine results and metadata. It also provides an integration with the
debug toolbar.


#### Requirements
debug toolbar. This bundle does not contain any pool implementation nor does it help you register cache pool services.
You maybe interested in [AdapterBundle](https://github.com/php-cache/adapter-bundle) which will help you configure and
register PSR-6 cache pools as services.

- PHP >= 5.5, < 7.1
- Symfony >= 2.6, ^3.0
- [Composer](http://getcomposer.org)
This bundle is a part of the PHP Cache organisation. To read about features like tagging and hierarchy support please
read the shared documentation at [www.php-cache.com](http://www.php-cache.com).

### To Install

You need to install and enable this bundle and also a PSR-6 cache implementation. In the example below we use the
[DoctrineAdapterBundle].

Run the following in your project root, assuming you have composer set up for your project
```sh
composer require cache/cache-bundle cache/doctrine-adapter-bundle
composer require cache/cache-bundle
```

Add the bundles to app/AppKernel.php
Add the bundle to app/AppKernel.php

```php
$bundles(
// ...
new Cache\CacheBundle\CacheBundle(),
new Cache\Adapter\DoctrineAdapterBundle\DoctrineAdapterBundle(),
// ...
);
```

To see all the config options, run `php app/console config:dump-reference cache` to view the config settings


#### A word on the cache implementation

This bundle does not register any cache services for you. This is done by [DoctrineAdapterBundle] you should look
at its documentation to see how you configure that bundle. Below in an example configuration:

```yml
cache_adapter_doctrine:
providers:
acme_redis_cache:
type: redis
database: 'foo'
acme_apc_cache:
type: apc
namespace: my_ns
```

### Configuration

#### Doctrine

This bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query. To use this
feature you need to install the [DoctrineBridge].

```sh
composer require cache/psr-6-doctrine-bridge
```


If you want Doctrine to use this as the result and query cache, you need this configuration:

```yml
cache:
doctrine:
enabled: true
metadata:
service_id: cache.provider.acme_redis_cache
entity_managers: [ default ] # the name of your entity_manager connection
document_managers: [ default ] # the name of your document_manager connection
result:
service_id: cache.provider.acme_redis_cache
entity_managers: [ default, read ] # you may specify multiple entity_managers
query:
service_id: cache.provider.acme_redis_cache
entity_managers: [ default ]
```

To use this with Doctrine's entity manager, just make sure you have `useResultCache` and/or `useQueryCache` set to true.

```php
$em = $this->get('doctrine.orm.entity_manager');
$q = $em->('SELECT u.* FROM Acme\User u');
$q->useResultCache(true, 3600);
$result = $q->getResult();

```

#### Session

This bundle even allows you to store your session data in one of your cache clusters. To enable:

```yml
cache:
session:
enabled: true
service_id: cache.provider.acme_redis_cache
ttl: 7200
```

#### Router

This bundle also provides router caching, to help speed that section up. To enable:

```yml
cache:
router:
enabled: true
service_id: cache.provider.acme_redis_cache
ttl: 86400
```

If you change any of your routes, you will need to clear the cache. If you use a cache implementation that supports
tagging (implements [TaggablePoolInterface](https://github.com/php-cache/taggable-cache/blob/master/src/TaggablePoolInterface.php))
you can clear the cache tagged with `routing`.

The routing cache will make the route lookup more performant when your application have many routes, especially many
dynamic routes. If you just have a few routes your performance will actually be worse enabling this.
Use [Blackfire](https://blackfire.io/) to profile your application to see if you should enable routing cache or not.


#### Logging

If you want to log all the interaction with the cache you may do so with the following configuration.

```yml
cache:
logging:
enabled: true
logger: 'logger' # Default service id to use for logging
level: 'info' # Default logging level
```

#### Annotation

To use a PSR-6 cache for your annotations, use the following confguration.

```yml
cache:
annotation:
enabled: true
service_id: cache.provider.acme_apc_cache

framwork:
annotations:
cache: cache.service.annotation
```

#### Serialization

To use a PSR-6 cache for the serialzer, use the following confguration.

```yml
cache:
serializer:
enabled: true
service_id: cache.provider.acme_apc_cache

framwork:
serializer:
cache: cache.service.serializer
```

#### Validation

To use a PSR-6 cache for the validation, use the following confguration.

```yml
cache:
validation:
enabled: true
service_id: cache.provider.acme_apc_cache

framwork:
validation:
cache: cache.service.validation
```


### Clearing the cache

If you want to clear the cache you can run the following commands.

```sh
php app/console cache:flush session
php app/console cache:flush router
php app/console cache:flush doctrine

echo "Or you could run:"
php app/console cache:flush all

echo "Run the following command to see all your options:"
php app/console cache:flush help
```

*Caution: If you are using a implementation that does not support tagging you will clear all with any of the above commands.*

### Need Help?

Create an issue if you've found a bug, or ping one of us on twitter: @aequasi or @TobiasNyholm


[DoctrineAdapterBundle]:https://github.com/php-cache/doctrine-adapter-bundle
[DoctrineBridge]:https://github.com/php-cache/doctrine-bridge
Read the documentation at [www.php-cache.com/symfony/cache-bundle](http://www.php-cache.com/en/latest/symfony/cache-bundle/).