cleardevice / slim-middleware-apc-cache
使用 APCu Cache 的 PHP Slim 2.* 微型框架缓存中间件,具有响应 ttl 设置
0.1.0
2016-04-30 16:19 UTC
Requires
- slim/slim: >=2.4.0
This package is not auto-updated.
Last update: 2024-09-14 18:36:59 UTC
README
使用 APCu Cache 的 PHP Slim 2.* 微型框架 的缓存中间件
灵感来自 https://github.com/palanik/SlimAPCCache
如何安装
- 更新你的
composer.json以要求cleardevice/slim-middleware-apc-cache包。 - 运行
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(); ?>