定制 beauty-framework/cache 二次开发

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

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

beauty-framework/cache

Composer 安装命令:

composer require beauty-framework/cache

包简介

Beauty Cache

关键字:

README 文档

README

A simple, PSR-16-compatible cache component for the Beauty Framework. Supports multiple cache backends (drivers), including in-memory array cache, Redis (via ext-redis), file cache, and RoadRunner key-value plugin.

Features

  • ✅ PSR-16 CacheInterface compliant
  • ✅ Simple driver system
  • ✅ Lazy connection resolution via CacheRegistry
  • ✅ Easy to extend with custom drivers
  • ✅ Clean, typed API

Supported Drivers

Driver ID Description TTL Support Flush Support Requirements
array In-memory array cache none
file File-based cache storage none
redis Redis-based cache via ext-redis PHP extension redis
roadrunner-kv RoadRunner KeyValue plugin (gRPC bridge) ⚠️ Partial RoadRunner + plugin
memory LRU cache in memory LRU cache

ℹ️ memcached is not supported out of the box but can be added as a custom driver (see example below).

Installation

composer require beauty-framework/cache

Configuration Example

use Beauty\Cache\CacheRegistry;
use Beauty\Cache\CacheFactory;
use Beauty\Cache\Driver\ArrayCacheDriver;
use Beauty\Cache\Driver\FileCacheDriver;
use Beauty\Cache\Driver\RedisCacheDriver;
use Beauty\Cache\Driver\KVCacheDriver;

$registry = new CacheRegistry(
    caches: [
        'redis' => ['driver' => 'redis', 'host' => '127.0.0.1', 'port' => 6379],
        'file' => ['driver' => 'file', 'directory' => __DIR__.'/storage/cache'],
        'kv' => ['driver' => 'roadrunner-kv', 'store' => 'memory']
    ],
    factory: new CacheFactory([
        new ArrayCacheDriver(),
        new FileCacheDriver(),
        new RedisCacheDriver(),
        new KVCacheDriver(),
    ]),
    default: 'redis'
);

$cache = $registry->get();
$cache->set('foo', 'bar');
echo $cache->get('foo'); // bar

Custom Driver Example: Memcached

use Memcached;
use Psr\SimpleCache\CacheInterface;

class Memcache implements CacheInterface 
{
    public function __construct(private Memcached $memcached) {}
    
    public function get(string $key, mixed $default = null): mixed {
        $value = $this->memcached->get($key);
        return $value === false ? $default : $value;
    }
    
    public function set(string $key, mixed $value, $ttl = null): bool {
        return $this->memcached->set($key, $value, $ttl ?? 0);
    }
    
    public function delete(string $key): bool {
        return $this->memcached->delete($key);
    }
    
    public function clear(): bool {
        return $this->memcached->flush();
    }
    
    public function getMultiple(iterable $keys, mixed $default = null): iterable {
        $results = [];
        foreach ($keys as $key) {
            $results[$key] = $this->get($key, $default);
        }
        return $results;
    }
    public function setMultiple(iterable $values, $ttl = null): bool {
        foreach ($values as $key => $value) {
            if (!$this->set($key, $value, $ttl)) return false;
        }
        return true;
    }
    
    public function deleteMultiple(iterable $keys): bool {
        foreach ($keys as $key) {
            if (!$this->delete($key)) return false;
        }
        return true;
    }
    
    public function has(string $key): bool {
        return $this->memcached->get($key) !== false;
    }
}    
use Beauty\Cache\Driver\CacheDriverInterface;
use Psr\SimpleCache\CacheInterface;
use Memcached;

class MemcachedCacheDriver implements CacheDriverInterface
{
    public function supports(string $driver): bool
    {
        return $driver === 'memcached';
    }

    public function make(array $config): CacheInterface
    {
        $memcached = new Memcached();
        $memcached->addServer($config['host'] ?? '127.0.0.1', $config['port'] ?? 11211);

        return new 
}

License

MIT

beauty-framework/cache 适用场景与选型建议

beauty-framework/cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cache」 「beauty」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 beauty-framework/cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 beauty-framework/cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 beauty-framework/cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-10