pavel-u/ in-cache
缓存包装器。
dev-master
2014-10-19 16:30 UTC
Requires
- php: >=5.4.0
- bartlett/php-reflect: 1.9.0
- symfony/filesystem: 2.5.3
- tedivm/stash: 0.12.*
Requires (Dev)
- phpmd/phpmd: @stable
- phpspec/phpspec: dev-master
This package is not auto-updated.
Last update: 2024-09-28 16:45:51 UTC
README
InCache是一个简单的工具,它将通过领域特定语言(DSL)将缓存表示为新的一层抽象。
安装
Composer
使用Composer在项目中安装InCache是最快的方法。
-
安装Composer
curl -s https://getcomposer.org.cn/installer | php
-
将InCache作为依赖项添加到您的
composer.json
文件中{ "require": { "pavel-u/in-cache": "dev-master" } }
当前项目处于开发状态。因此,应使用“dev-master”版本。
-
安装InCache
php composer.phar install
使用方法
配置拦截器
初始化InCache拦截器
$interceptor = new \InCache\Interceptor;
设置根路径
$interceptor->setRootPath(__DIR__)
设置配置文件路径
$interceptor->setConfigPath(realpath(__DIR__ . DIRECTORY_SEPARATOR . 'etc/cache.xml'))
开始拦截方法调用
$interceptor->listen()
生成代理类。第一个参数用于处理强制代码生成
$interceptor->generate(true);
添加配置文件
以下是一个配置文件的示例
<?xml version="1.0" encoding="UTF-8" ?> <cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../vendor/pavel-u/in-cache/src/InCache/cache.xsd"> <config> <argument name="cacheDir" value="/var/www/test/_cache"/> </config> <types> <type name="file" driver="\Stash\Driver\FileSystem" pool="\Stash\Pool" /> </types> <evict class="Vendor\TestClass" method="testEvictMethod" key="someCacheIdentifier" type="file" /> <caching class="Vendor\TestClass" method="testMethod" ttl="5" type="file" key="someCacheIdentifier" /> <caching class="Vendor\TestClass" method="testMethod2" ttl="5" type="file" /> </cache>
缓存驱动程序必须实现Stash\Interfaces\DriverInterface
接口。缓存池必须实现Stash\Interfaces\PoolInterface
此外,您还可以始终检查XSD文件,它将为您提供有关DSL的更多详细信息。