PHPackages                             orchestra/memory - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. orchestra/memory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

orchestra/memory
================

Memory Component for Orchestra Platform

v6.0.0(5y ago)11150.2k↓20%411MITPHPPHP ^7.3 || ^8.0

Since Jun 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/orchestral/memory)[ Packagist](https://packagist.org/packages/orchestra/memory)[ Docs](http://orchestraplatform.com/docs/latest/components/memory/)[ Fund](https://paypal.me/crynobone)[ Fund](https://liberapay.com/crynobone)[ RSS](/packages/orchestra-memory/feed)WikiDiscussions 6.x Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (54)Used By (11)

Memory Component for Orchestra Platform
=======================================

[](#memory-component-for-orchestra-platform)

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.

[![tests](https://github.com/orchestral/memory/workflows/tests/badge.svg?branch=6.x)](https://github.com/orchestral/memory/actions?query=workflow%3Atests+branch%3A6.x)[![Latest Stable Version](https://camo.githubusercontent.com/7133ef6245aa6eace9e854cbcf5e09ce074d024bd92e8b82da6bdacd7f3f8a0a/68747470733a2f2f706f7365722e707567782e6f72672f6f72636865737472612f6d656d6f72792f76657273696f6e)](https://packagist.org/packages/orchestra/memory)[![Total Downloads](https://camo.githubusercontent.com/1fb0b4d4a5524d9ca501cf95a80fe4a315f3b7bdf43639b1be58fca1764c7237/68747470733a2f2f706f7365722e707567782e6f72672f6f72636865737472612f6d656d6f72792f646f776e6c6f616473)](https://packagist.org/packages/orchestra/memory)[![Latest Unstable Version](https://camo.githubusercontent.com/64b456e362564acbcd1d68d7a21f4444961759b254de4d9d93c93e1abbcbf112/68747470733a2f2f706f7365722e707567782e6f72672f6f72636865737472612f6d656d6f72792f762f756e737461626c65)](//packagist.org/packages/orchestra/memory)[![License](https://camo.githubusercontent.com/3723bcb5ac7f1d6a25b80fc9e542299f74ab4d820563a419d14938f2a6efd510/68747470733a2f2f706f7365722e707567782e6f72672f6f72636865737472612f6d656d6f72792f6c6963656e7365)](https://packagist.org/packages/orchestra/memory)[![Coverage Status](https://camo.githubusercontent.com/b290eed2bd93723ebbdbb01c8c5538cf917203167b420913f6e970f2e4106b7d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f72636865737472616c2f6d656d6f72792f62616467652e7376673f6272616e63683d362e78)](https://coveralls.io/github/orchestral/memory?branch=6.x)

Version Compatibility
---------------------

[](#version-compatibility)

LaravelMemory5.5.x3.5.x5.6.x3.6.x5.7.x3.7.x5.8.x3.8.x6.x4.x7.x5.x8.x6.xInstallation
------------

[](#installation)

To install through composer, run the following command from terminal:

```
composer require "orchestra/memory"
```

Configuration
-------------

[](#configuration)

Next add the service provider in `config/app.php`.

```
'providers' => [

  // ...

  Orchestra\Memory\MemoryServiceProvider::class,

],
```

### Aliases

[](#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

[](#migrations)

Before we can start using Memory Component, please run the following:

php artisan migrate

### Publish Configuration

[](#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
-----

[](#usage)

### Creating Instance

[](#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)

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)

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

[](#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

[](#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.

```
