bnomei/kirby3-php-cachedriver
Composer 安装命令:
composer require bnomei/kirby3-php-cachedriver
包简介
PHP based Cache-Driver
关键字:
README 文档
README
Elephant - a highly performant PHP Cache Driver for Kirby
Installation
- unzip master.zip as folder
site/plugins/kirby3-php-cachedriveror git submodule add https://github.com/bnomei/kirby3-php-cachedriver.git site/plugins/kirby3-php-cachedriverorcomposer require bnomei/kirby3-php-cachedriver
Usage
Cache methods
$cache = \Bnomei\PHPCache::singleton(); // or $cache = elephant(); $cache->set('key', 'value', $expireInMinutes); $value = elephant()->get('key', $default); elephant()->remove('key'); elephant()->flush();
Cache file(s)
All data is written at the end of the PHP script life-cycle. This does not count against your script execution time, but for example, when you change the value in the cache with each request, writing that big file every time time might prove inefficient. Furthermore, more incremental updates will be written during script execution depending on the mono_dump setting. Additions to the cache will also be written in temporary files to improve the stability of the cache.
Serialization of data
This plugin defaults to a simple serialization logic, which is quick but only serializes primitive data types, closures, and objects that have a toArray()-method like Kirby\Cms\Field and Kirby\Toolkit\Obj. This should be enough for most use-cases.
If you need broader support set bnomei.php-cachedriver.serialize to json which will en- and decode your data as JSON before storing it. That is a bit slower but will ensure your data contains only primitive types without the hassle of serializing it manually before caching it.
OPCache
Make sure OPCache is configured to load the PHP files from the cache without any delay. Most probably you will have to set these values in your user.ini or something similar! If you do not set these values, you might have outdated data being loaded from php files cached by OPCache instead of loading the right ones you want from disk.
opcache.enable=1 opcache.enable_cli=0 # default is 0, leave it like that opcache.validate_timestamps=1 opcache.revalidate_freq=0 # default is 2, 0 => on every request
Thanks, Al, for helping me get these config values right.
Benchmark
elephant()->benchmark(1000);
php : 0.03383207321167 file : 2.3811981678009
ATTENTION: This will create and remove a lot of cache files and php-cache files
No cache when debugging
When Kirbys global debug config is set to true the complete plugin cache will be flushed and no caches will be read. But entries will be created.
How to use Elephant with Lapse or Boost
You need to set the cache driver for the lapse plugin to php. Please be aware that the mono-mode is not suited for concurrent writes.
site/config/config.php
<?php return [ 'bnomei.lapse.cache' => ['type' => 'php'], 'bnomei.boost.cache' => ['type' => 'php'], //... other options ];
Setup Content-File Cache
Use Kirby 3 Boost to set up a cache for content files.
Settings
| bnomei.php-cachedriver. | Default | Description |
|---|---|---|
| mono_dump | 2048 |
write to cache file every n changes |
| check_opcache | true |
check OPCache settings |
| serialize | 'primitive' |
which is fastest or 'json' for less hassle |
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
bnomei/kirby3-php-cachedriver 适用场景与选型建议
bnomei/kirby3-php-cachedriver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.73k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2021 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「php」 「cache」 「value」 「key」 「Opcache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bnomei/kirby3-php-cachedriver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bnomei/kirby3-php-cachedriver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bnomei/kirby3-php-cachedriver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
repository php library
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 2.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-10