yiisoft/cache-apcu
Composer 安装命令:
composer require yiisoft/cache-apcu
包简介
Yii Caching Library - APCu Handler
关键字:
README 文档
README
Yii Cache Library - APCu Handler
This package uses the PHP APCu extension and implements PSR-16 cache.
This option can be considered as the fastest one when dealing with a cache for a centralized thick application (e.g. one server, no dedicated load balancers, etc.).
Requirements
- PHP 8.0 or higher.
APCuPHP extension.
Installation
The package could be installed with Composer:
composer require yiisoft/cache-apcu
General usage
The package does not contain any additional functionality for interacting with the cache, except those defined in the PSR-16 interface.
$cache = new \Yiisoft\Cache\Apcu\ApcuCache(); $parameters = ['user_id' => 42]; $key = 'demo'; // try retrieving $data from cache $data = $cache->get($key); if ($data === null) { // $data is not found in cache, calculate it from scratch $data = calculateData($parameters); // store $data in cache for an hour so that it can be retrieved next time $cache->set($key, $data, 3600); } // $data is available here
In order to delete value you can use:
$cache->delete($key); // Or all cache $cache->clear();
To work with values in a more efficient manner, batch operations should be used:
getMultiple()setMultiple()deleteMultiple()
This package can be used as a cache handler for the Yii Caching Library.
Cleaning up APCu cache
Typically the web processes are separate from CLI so these do not share the same cache instance. Thus, special
handling in the web is needed for the case. First, a web-acessible script apc_clear.php like the following:
<?php if (in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); echo json_encode(['success' => true]); }
And finally, you need some code that calls it:
$url = 'http://localhost/apc_clear.php'; $result = json_decode(file_get_contents($url)); if (empty($result['success'])) { echo "There was an error cleaning up APCu cache.\n". }
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Cache Library - APCu Handler is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
yiisoft/cache-apcu 适用场景与选型建议
yiisoft/cache-apcu 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.94k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2019 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「cache」 「yii」 「apcu」 「psr-16」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiisoft/cache-apcu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiisoft/cache-apcu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiisoft/cache-apcu 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
repository php library
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Laravel 5 - Repositories to the database layer
Priveate for SkeekS CMS
C3JS Chart for Yii Framework 2.0
统计信息
- 总下载量: 7.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 19
- 依赖项目数: 3
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-08-13