Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/openclassrooms/doctrinecacheextension
https://github.com/openclassrooms/doctrinecacheextension
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/openclassrooms/doctrinecacheextension
- Owner: OpenClassrooms
- License: mit
- Created: 2015-08-09T16:06:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T16:09:08.000Z (3 months ago)
- Last Synced: 2024-11-09T04:12:33.319Z (9 days ago)
- Language: PHP
- Size: 18.6 KB
- Stars: 0
- Watchers: 26
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Doctrine Cache Extension
[![Build Status](https://travis-ci.org/OpenClassrooms/DoctrineCacheExtension.svg?branch=master)](https://travis-ci.org/OpenClassrooms/DoctrineCacheExtension)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d595725d-9e23-4386-b0ba-444e1a118f60/mini.png)](https://insight.sensiolabs.com/projects/d595725d-9e23-4386-b0ba-444e1a118f60)
[![Coverage Status](https://coveralls.io/repos/OpenClassrooms/DoctrineCacheExtension/badge.svg?branch=master&service=github)](https://coveralls.io/github/OpenClassrooms/DoctrineCacheExtension?branch=master)The Doctrine Cache extension adds the following features to Doctrine Cache implementation:
- Default lifetime
- Fetch with a namespace
- Save with a namespace
- Cache invalidation through namespace strategy## Installation
The easiest way to install DoctrineCacheExtension is via [composer](http://getcomposer.org/).Create the following `composer.json` file and run the `php composer.phar install` command to install it.
```json
{
"require": {
"openclassrooms/doctrine-cache-extension": "*"
}
}
```
```php## Usage
### Instantiation
OpenClassrooms CacheProviderDecorator needs a Doctrine CacheProvider to be instantiated.
```php
$cacheProvider = new ArrayCache();
$cacheProviderDecorator = new CacheProviderDecorator($cacheProvider);
```A factory can be used to accomplish this.
```php
$factory = new CacheProviderDecoratorFactory();
$cacheProvider = $factory->create('array');
```### Default lifetime
Specify lifetime in the constructor:
```php
$cacheProviderDecorator = new CacheProviderDecorator($cacheProvider, 100);
$cacheProviderDecorator->save($id, $data);
```
Or via the factory:
```php
$cacheProvider = $factory->create('array', 100);
```
Or specify a default lifetime for all the cache providers:
```php
$factory = new CacheProviderDecoratorFactory();
$factory->setDefaultLifetime(100);
```
### Fetch with namespace
```php
$data = $cacheProviderDecorator->fetchWithNamespace($id, $namespaceId);
```### Save with namespace
```php
// Namespace and life time can be null
$data = $cacheProviderDecorator->saveWithNamespace($id, $data, $namespaceId, $lifeTime);
```### Cache invalidation
```php
$cacheProviderDecorator->invalidate($namespaceId);
```