定制 nytris/cache 二次开发

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

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

nytris/cache

最新稳定版本:v0.0.6

Composer 安装命令:

composer create-project nytris/cache

包简介

README 文档

README

Build Status

Implements a ReactPHP cache using any PSR-6-compliant cache such as Symfony Cache.

Usage

Install this package with Composer:

$ composer require nytris/cache

When using Nytris platform (recommended)

Configure Nytris platform:

nytris.config.php

<?php

declare(strict_types=1);

use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Nytris\Cache\Adapter\ReactCacheAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/'));

$bootConfig->installPackage(new MyNytrisPackage(
    // Using Symfony Cache adapter as an example.
    cachePoolFactory: fn (string $cachePath) => new ReactCacheAdapter(
        new FilesystemAdapter(
            'my_cache_key',
            0,
            $cachePath
        )
    )
));

return $bootConfig;

LightApcuAdapter

This is a thin, lightweight, minimal wrapper around APCu that implements the PSR-6 interface.

Usage:

<?php

declare(strict_types=1);

use Nytris\Cache\Adapter\LightApcuAdapter;

$adapter = new LightApcuAdapter(
    namespace: 'my_namespace', // Defaults to the empty string.
    defaultLifetime: 3600      // Defaults to 0 / no expiry.
);

$cacheItem = $adapter->getItem('my_key');
$cacheItem->set('my_value');
$cacheItem->expiresAfter(2); // Set to expire 2 seconds from now.

$adapter->save($cacheItem);

Caveats

  • PSR-6 cache adapters may block, if so then the ReactPHP event loop will be blocked. It is the responsibility of the consuming application to not use PSR cache adapters that block.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-27