定制 papimod/cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

papimod/cache

最新稳定版本:v2.1.0

Composer 安装命令:

composer require papimod/cache

包简介

Module Papi

README 文档

README

Description

Enable routes and DI caching in your papi in production.

By default you should add .cache/ into your .gitignore file

I also recommend reading the section "deployment in production".

Prerequisites Modules

Configuration

ENVIRONMENT (.ENV)

Required No
Type PRODUCTION, DEVELOPMENT, TEST or null
Description Enable caching when set to PRODUCTION
Default null

CACHE_DIRECTORY (.ENV)

Required No
Type string
Description Cache directory path
Default {{project_directory}}/.cache

CACHE_TIMEOUT (.ENV)

Required No
Type Int
Description Time in seconds between cache refreshes
Default 86400

API

Usage

You can add the following options to your .env file:

ENVIRONMENT=PRODUCTION
CACHE_DIRECTORY=tmp
CACHE_TIMEOUT=900

Import the module when creating your application:

require __DIR__ . "/../vendor/autoload.php";

use Papi\PapiBuilder;
use Papimod\Dotenv\DotEnvModule;
use Papimod\Cache\CacheModule;
use function DI\create;

define("PAPI_DOTENV_DIRECTORY", __DIR__); # Optionnal
define("PAPI_DOTENV_FILE", ".env"); # Optionnal

$builder = new PapiBuilder();

$builder->setModule(
        DotEnvModule::class,
        CacheModule::class
    )
    ->build()
    ->run();

Use the dedicated service anywhere:

final class MyService
{
    private readonly CacheService $cache_service;

    public function __construct(CacheService $cache_service)
    {
        $this->cache_service = $cache_service;
    }

    public increment(): string
    {
        $foo = $this->cache_service->get('foo');

        if($foo !== null) {
            $foo++
        } else {
            $foo = 1;
        }

        $this->cache_service->set('foo', $foo, 120);
    }
}

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-12-04