rollerworks/metadata-doctrine-cache

此包已被弃用且不再维护。未建议替代包。

Rollerworks Metadata 组件的 Doctrine 缓存适配器

v0.2 2015-09-17 12:23 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:51:26 UTC


README

Build Status

本包为 Rollerworks Metadata 组件提供 Doctrine 缓存适配器,请参阅 Rollerworks Metadata 组件

安装

要安装此包,请将 rollerworks/metadata-doctrine-cache 添加到您的 composer.json 文件中

$ php composer.phar require rollerworks/metadata-doctrine-cache

然后,您可以从存放 composer.json 文件的目录中运行 Composer 的 update 命令来安装新的依赖项

$ php composer update rollerworks/metadata-doctrine-cache

现在,Composer 将自动下载所有必需的文件,并为您安装它们。

使用

require 'vendor/autoload.php';

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\ChainCache;
use Doctrine\Common\Cache\FilesystemCache;
use Rollerworks\Component\Metadata\CacheableMetadataFactory;
use Rollerworks\Component\Metadata\Cache\Validator\AlwaysFreshValidator;
use Rollerworks\Component\Metadata\Cache\ArrayCache;

$cacheDirectory = ...;

// The Doctrine cache library.
$doctrineCache = new ChainCache(
    [
        // Include the ArrayCache as the ChainCache will populate all the previous cache layers.
        // So if the `FilesystemCache` has a match it will populate the faster ArrayCache.
        new ArrayCache(),

        // Saves the cache in the filestem.
        new FilesystemCache($cacheDirectory),
    ]
);

// Rollerworks\Component\Metadata\Cache\CacheProvider
$cache = Rollerworks\Component\Metadata\Driver\Cache\DoctrineCache($doctrineCache);

// Rollerworks\Component\Metadata\Driver\MappingDriver
$driver = ...;

// Rollerworks\Component\Metadata\Cache\FreshnessValidator
$freshnessValidator = ...;

$metadataFactory = new CacheableMetadataFactory($driver, $doctrineCache, $freshnessValidator);

就是这样。

运行测试

每次您打开 pull-request 时,Travis-CI 都会自动运行测试。

可以使用 PHPUnit 运行测试,确保在运行 Composer 时使用 --prefer-source 选项,因为一些测试用的类在存档包中不可用。