cleardevice / slim-middleware-apc-cache

使用 APCu Cache 的 PHP Slim 2.* 微型框架缓存中间件,具有响应 ttl 设置

0.1.0 2016-04-30 16:19 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:59 UTC


README

Latest Stable Version License

使用 APCu Cache 的 PHP Slim 2.* 微型框架 的缓存中间件

灵感来自 https://github.com/palanik/SlimAPCCache

如何安装

  1. 更新你的 composer.json 以要求 cleardevice/slim-middleware-apc-cache 包。
  2. 运行 composer install 以将 SlimAPCCache 添加到你的 vendor 文件夹。
{
  "require": {
    "cleardevice/slim-middleware-apc-cache": "0.1.0.*"
  }
}

##如何使用此中间件

<?php
require ('./vendor/autoload.php');

$app = new \Slim\Slim();

use cleardevice\SlimMiddlewareAPCCache\SlimMiddlewareAPCCache;

$app->add(new SlimMiddlewareAPCCache(60, 'myapp_prefix_');

$app->get('/foo_1', function () use ($app) {
    echo "Hello Bar, default ttl";
});

$app->get('/foo_2', function () use ($app) {
    echo "Hello Bar, custom cache ttl";
    $this->app->container->set(SlimMiddlewareAPCCache::TTL_KEY, 3600);
});

$app->get('/foo_3', function () use ($app) {
    echo "Hello Bar, no cache";
    $this->app->container->set(SlimMiddlewareAPCCache::TTL_KEY, SlimMiddlewareAPCCache::TTL_NO_CACHE);
});

$app->get('/foo_4', function () use ($app) {
    echo "Hello Bar, permanent cache";
    $this->app->container->set(SlimMiddlewareAPCCache::TTL_KEY, SlimMiddlewareAPCCache::TTL_PERMANENT_CACHE);
});

$app->run();
?>