orchestra / memory
Memory Component for Orchestra Platform
Fund package maintenance!
Liberapay
paypal.me/crynobone
Installs: 149 044
Dependents: 11
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- illuminate/database: ^8.37
- orchestra/contracts: ^6.0
- orchestra/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^6.17
- dev-master / 7.0.x-dev
- 6.x-dev
- v6.0.0
- 5.x-dev
- v5.0.0
- 4.x-dev
- v4.0.0
- 3.8.x-dev
- v3.8.0
- 3.7.x-dev
- v3.7.1
- v3.7.0
- 3.6.x-dev
- v3.6.1
- v3.6.0
- 3.5.x-dev
- v3.5.0
- 3.4.x-dev
- v3.4.0
- 3.3.x-dev
- v3.3.1
- v3.3.0
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
This package is auto-updated.
Last update: 2024-12-18 02:09:28 UTC
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
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\Handler
which add some boilerplate code on your custom handler.