orchestra/memory
Composer 安装命令:
composer require orchestra/memory
包简介
Memory Component for Orchestra Platform
README 文档
README
Memory Component handles runtime configuration either using "in memory" Runtime or database using Cache, Fluent Query Builder or Eloquent ORM. Instead of just allowing static configuration to be used, Memory Component allow those configuration to be persistent in between request by utilising multiple data storage option either through cache or database.
Version Compatibility
| Laravel | Memory |
|---|---|
| 5.5.x | 3.5.x |
| 5.6.x | 3.6.x |
| 5.7.x | 3.7.x |
| 5.8.x | 3.8.x |
| 6.x | 4.x |
| 7.x | 5.x |
| 8.x | 6.x |
Installation
To install through composer, run the following command from terminal:
composer require "orchestra/memory"
Configuration
Next add the service provider in config/app.php.
'providers' => [ // ... Orchestra\Memory\MemoryServiceProvider::class, ],
Aliases
You might want to add Orchestra\Support\Facades\Memory to class aliases in config/app.php:
'aliases' => [ // ... 'Memory' => Orchestra\Support\Facades\Memory::class, ],
Migrations
Before we can start using Memory Component, please run the following:
php artisan migrate
Publish Configuration
Optionally, you can also publish the configuration file if there any requirement to change the default:
php artisan vendor:publish --provider="Orchestra\\Memory\\MemoryServiceProvider"
Usage
Creating Instance
Below are list of possible ways to use Memory Component:
$runtime = Memory::make('runtime'); $fluent = Memory::make('fluent'); $eloquent = Memory::make('eloquent'); $cache = Memory::make('cache');
However, most of the time you wouldn't need to have additional memory instance other than the default which is using orchestra_options table.
$memory = Memory::make();
When using with Orchestra Platform,
Memory::make()would be used throughout the application.
Storing Items
Storing items in the Memory Component is simple. Simply call the put method:
$memory->put('site.author', 'Taylor'); // or you can also use Memory::put('site.author', 'Taylor');
The first parameter is the key to the config item. You will use this key to retrieve the item from the config. The second parameter is the value of the item.
Retrieving Items
Retrieving items from Memory Component is even more simple than storing them. It is done using the get method. Just mention the key of the item you wish to retrieve:
$name = $memory->get('site.author'); // or you can also use $name = Memory::get('site.author');
By default, NULL will be returned if the item does not exist. However, you may pass a different default value as a second parameter to the method:
$name = $memory->get('site.author', 'Fred');
Now, "Fred" will be returned if the "site.author" item does not exist.
Removing Items
Need to get rid of an item? No problem. Just mention the name of the item to the forget method:
$memory->forget('site.author'); // or you can also use Memory::forget('site.author');
Extending Memory
There might be requirement that a different type of storage engine would be use for memory instance, you can extending it by adding your own handler.
<?php use Orchestra\Contracts\Memory\Handler; class AcmeMemoryHandler implements Handler { // Add your implementation } Memory::extend('acme', function ($app, $name) { return new Orchestra\Memory\Provider( new AcmeMemoryHandler($name) ); }); // Now you can use it as $acme = Memory::make('acme.default');
You can also extends
Orchestra\Memory\Handlerwhich add some boilerplate code on your custom handler.
orchestra/memory 适用场景与选型建议
orchestra/memory 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 150.12k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2013 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 「laravel」 「orchestra-platform」 「orchestral」 「database-config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 orchestra/memory 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 orchestra/memory 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 orchestra/memory 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Component for Orchestra Platform
Orchestra Platform Foundation
Orchestra Platform
A Zend Framework module to quickly and easily set PHP settings.
CMS Extension for Orchestra Platform
Contracts for Orchestra Platform
统计信息
- 总下载量: 150.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 19
- 依赖项目数: 11
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-04-11