fyre/cache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fyre/cache

Composer 安装命令:

composer require fyre/cache

包简介

A cache library.

README 文档

README

FyreCache is a free, open-source cache library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/cache

In PHP:

use Fyre\Cache\CacheManager;

Basic Usage

$cacheManager = new CacheManager($container);

Default configuration options will be resolved from the "Cache" key in the Config.

The cache will be disabled by default if the `"App.debug" key is set in the Config.

Autoloading

It is recommended to bind the CacheManager to the Container as a singleton.

$container->singleton(CacheManager::class);

Any dependencies will be injected automatically when loading from the Container.

$cacheManager = $container->use(CacheManager::class);

Methods

Build

Build a Cacher.

  • $options is an array containing configuration options.
$cacher = $cacheManager->build($options);

Cacher dependencies will be resolved automatically from the Container.

Clear

Clear all instances and configs.

$cacheManager->clear();

Disable

Disable the cache.

$cacheManager->disable();

If the cache is disabled, the use method will always return a NullCacher.

Enable

Enable the cache.

$cacheManager->enable();

Get Config

Get a Cacher config.

  • $key is a string representing the Cacher key.
$config = $cacheManager->getConfig($key);

Alternatively, if the $key argument is omitted an array containing all configurations will be returned.

$config = $cacheManager->getConfig();

Has Config

Determine whether a Cacher config exists.

  • $key is a string representing the Cacher key, and will default to CacheManager::DEFAULT.
$hasConfig = $cacheManager->hasConfig($key);

Is Enabled

Determine whether the cache is enabled.

$cacheManager->isEnabled();

Is Loaded

Determine whether a Cacher instance is loaded.

  • $key is a string representing the Cacher key, and will default to CacheManager::DEFAULT.
$isLoaded = $cacheManager->isLoaded($key);

Set Config

Set the Cacher config.

  • $key is a string representing the Cacher key.
  • $options is an array containing configuration options.
$cacheManager->setConfig($key, $options);

Unload

Unload a Cacher.

  • $key is a string representing the Cacher key, and will default to CacheManager::DEFAULT.
$cacheManager->unload($key);

Use

Load a shared Cacher instance.

  • $key is a string representing the Cacher key, and will default to CacheManager::DEFAULT.
$cacher = $cacheManager->use($key);

Cacher dependencies will be resolved automatically from the Container.

Cachers

You can load a specific cacher by specifying the className option of the $options variable above.

Custom cachers can be created by extending \Fyre\Cache\Cacher, ensuring all below methods are implemented.

Clear

Clear the cache.

$cleared = $cacher->clear();

Decrement

Decrement a cache value.

  • $key is a string representing the cache key.
  • $amount is a number indicating the amount to decrement by, and will default to 1.
$value = $cacher->decrement($key, $amount);

Delete

Delete an item from the cache.

  • $key is a string representing the cache key.
$deleted = $cacher->delete($key);

Delete Multiple

Delete multiple items from the cache.

  • $keys is an array containing the cache keys.
$deleted = $cacher->deleteMultiple($keys);

Get

Retrieve a value from the cache.

  • $key is a string representing the cache key.
  • $default is the default value to return, and will default to null.
$value = $cacher->get($key, $default);

Get Multiple

Retrieve multiple values from the cache.

  • $keys is an array containing the cache keys.
  • $default is the default value to return, and will default to null.
$values = $cacher->getMultiple($keys, $default);

Has

Determine whether an item exists in the cache.

  • $key is a string representing the cache key.
$has = $cacher->has($key);

Increment

Increment a cache value.

  • $key is a string representing the cache key.
  • $amount is a number indicating the amount to increment by, and will default to 1.
$value = $cacher->increment($key, $amount);

Remember

Retrieve an item from the cache, or save a new value if it doesn't exist.

  • $key is a string representing the cache key.
  • $callback is the callback method to generate the value.
  • $expire is a number indicating the number of seconds the value will be valid, and will default to null.
$value = $cacher->remember($key, $callback, $expire);

Set

Set an item in the cache.

  • $key is a string representing the cache key.
  • $value is the value to save in the cache.
  • $expire is a number indicating the number of seconds the value will be valid, and will default to null.
$saved = $cacher->set($key, $value, $expire);

Set Multiple

Set multiple items in the cache.

  • $values is an array containing the values to save in the cache.
  • $expire is a number indicating the number of seconds the value will be valid, and will default to null.
$saved = $cacher->setMultiple($values, $expire);

Size

Get the size of the cache.

$size = $cacher->size();

Array

The Array cacher can be loaded using customer configuration.

  • $options is an array containing configuration options.
    • className must be set to \Fyre\Cache\Handlers\ArrayCacher.
    • expire is a number indicating the default cache timeout.
$container->use(Config::class)->set('Cache.array', $options);

File

The File cacher can be loaded using custom configuration.

  • $options is an array containing configuration options.
    • className must be set to \Fyre\Cache\Handlers\FileCacher.
    • expire is a number indicating the default cache timeout.
    • prefix is a string representing the cache key prefix.
    • path is a string representing the directory path, and will default to "/tmp/cache".
    • mode is a number indicating the cache file permissions, and will default to 0640.
$container->use(Config::class)->set('Cache.file', $options);

Memcached

The Memcached cacher can be loaded using custom configuration.

  • $options is an array containing configuration options.
    • className must be set to \Fyre\Cache\Handlers\MemcachedCacher.
    • expire is a number indicating the default cache timeout.
    • prefix is a string representing the cache key prefix.
    • host is a string representing the Memcached host, and will default to "127.0.0.1".
    • port is a number indicating the Memcached port, and will default to 11211.
    • weight is a number indicating the server weight, and will default to 1.
$container->use(Config::class)->set('Cache.memcached', $options);

Redis

The Redis cacher can be loaded using custom configuration.

  • $options is an array containing configuration options.
    • className must be set to \Fyre\Cache\Handlers\RedisCacher.
    • expire is a number indicating the default cache timeout.
    • prefix is a string representing the cache key prefix.
    • host is a string representing the Redis host, and will default to "127.0.0.1".
    • password is a string representing the Redis password.
    • port is a number indicating the Redis port, and will default to 6379.
    • database is a string representing the Redis database.
    • timeout is a number indicating the connection timeout.
    • persist is a boolean indicating whether to use a persistent connection, and will default to true.
    • tls is a boolean indicating whether to use a tls connection, and will default to true.
    • ssl is an array containing SSL options.
      • key is a string representing the path to the key file.
      • cert is a string representing the path to the certificate file.
      • ca is a string representing the path to the certificate authority file.
$container->use(Config::class)->set('Cache.redis', $options);

fyre/cache 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-31