Register Plugin

<?php

use Bartlett\Reflect;
use Bartlett\Reflect\Plugin\Cache\CachePlugin;

$reflect = new Reflect;
$reflect->addSubscriber( new CachePlugin($cache) );

Where $cache is an instance of object that must implement interface Bartlett\Reflect\Plugin\Cache\CacheStorageInterface.

Use the Bartlett\Reflect\Plugin\Cache\DefaultCacheStorage object unless you want to change the cache storage behavior.

Doctrine Adapter

Use one of the most famous caching solution, provided by the Doctrine project.

<?php

use Bartlett\Reflect;
use Bartlett\Reflect\Plugin\Cache\CachePlugin;
use Bartlett\Reflect\Plugin\Cache\DefaultCacheStorage;
use Bartlett\Reflect\Cache\DoctrineCacheAdapter;

use Doctrine\Common\Cache\FilesystemCache;

$doctrineCache = new DoctrineCacheAdapter($backend);

$cache = new DefaultCacheStorage($doctrineCache);

$reflect = new Reflect;
$reflect->addSubscriber( new CachePlugin($cache) );

Where $backend is an instance of object that must implement interface Doctrine\Common\Cache\CacheProvider.

File cache

Doctrine File backend to store your Reflect results in the local file system.

<?php

use Bartlett\Reflect;
use Bartlett\Reflect\Plugin\Cache\CachePlugin;
use Bartlett\Reflect\Plugin\Cache\DefaultCacheStorage;
use Bartlett\Reflect\Cache\DoctrineCacheAdapter;

use Doctrine\Common\Cache\FilesystemCache;

$backend = new FilesystemCache(sys_get_temp_dir() . '/bartlett/cache');

$doctrineCache = new DoctrineCacheAdapter($backend);

$cache = new DefaultCacheStorage($doctrineCache);

$reflect = new Reflect;
$reflect->addSubscriber( new CachePlugin($cache) );

In the source code above, we use the standard Doctrine File cache provider, and store results in the default system temporary directory ( see php sys_get_temp_dir() function ).