Skip to content

emilyreese/DoctrineCacheExtension

 
 

Repository files navigation

Doctrine Cache Extension

Build Status SensioLabsInsight Coverage Status

Doctrine Cache extension adds 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.

Create the following composer.json file and run the php composer.phar install command to install it.

{
    "require": {
        "openclassrooms/doctrine-cache-extension": "*"
    }
}
<?php
require 'vendor/autoload.php';

use OpenClassrooms\DoctrineCacheExtension\CacheProviderDecorator;

//do things

Instantiation

OpenClassrooms CacheProviderDecorator needs a Doctrine CacheProvider to be instantiated.

$cacheProvider = new ArrayCache();
$cacheProviderDecorator = new CacheProviderDecorator($cacheProvider);

A factory can be used.

$factory = new CacheProviderDecoratorFactory();
$cacheProvider = $factory->create('array');

Default lifetime

Specify lifetime in the constructor:

$cacheProviderDecorator = new CacheProviderDecorator($cacheProvider, 100);
$cacheProviderDecorator->save($id, $data);

Or using the factory:

$cacheProvider = $factory->create('array', 100);

Or specify a default lifetime for all the cache providers:

$factory = new CacheProviderDecoratorFactory();
$factory->setDefaultLifetime(100);

Fetch with namespace

$data = $cacheProviderDecorator->fetchWithNamespace($id, $namespaceId);

Save with namespace

// Namespace and life time can be null
$data = $cacheProviderDecorator->saveWithNamespace($id, $data, $namespaceId, $lifeTime);

Cache invalidation

$cacheProviderDecorator->invalidate($namespaceId);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%