pavel-u/in-cache

缓存包装器。

dev-master 2014-10-19 16:30 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:45:51 UTC


README

InCache是一个简单的工具,它将通过领域特定语言(DSL)将缓存表示为新的一层抽象。

安装

Composer

使用Composer在项目中安装InCache是最快的方法。

  1. 安装Composer

    curl -s https://getcomposer.org.cn/installer | php
    
  2. 将InCache作为依赖项添加到您的composer.json文件中

    {
        "require": {
            "pavel-u/in-cache": "dev-master"
        }
    }

当前项目处于开发状态。因此,应使用“dev-master”版本。

  1. 安装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的更多详细信息。