2017 © Pedro PelĂĄez
 

library storage

Store and retrieve values, using different/multiple storage backends.

image

icanboogie/storage

Store and retrieve values, using different/multiple storage backends.

  • Saturday, March 17, 2018
  • by olvlvl
  • Repository
  • 3 Watchers
  • 5 Stars
  • 12,090 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 2 Forks
  • 1 Open issues
  • 13 Versions
  • 4 % Grown

The README.md

Storage

Release Build Status Code Quality Code Coverage Packagist, (*1)

icanboogie/storage defines an API to store and retrieve values, while offering different storage backends., (*2)

Values can be stored using the runtime memory, Redis, APC, the file system
 Storage collections retrieve and store values using multiple different storage instances, that usually range from the less expensive (and the more volatile) to the more expensive (and the more durable)., (*3)

This package includes the following storage backends:, (*4)

Storage

A storage is used to store a value and retrieve it later. A unique key is used to identify the value. Different storage store values using different mechanisms, and sometimes for a different period of time. It's always a good idea to choose the storage that best fits a situation, according to the persistence requirement and the expensiveness of the storage., (*5)

Note: Storage classes implement the Storage interface, including the StorageCollection class., (*6)

<?php

use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null
$storage->store('icanboogie', "Yes Sir, I Can Boogie");
$storage->retrieve('icanboogie');   // "Yes Sir, I Can Boogie"
$storage->eliminate('icanboogie');
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null

Time To Live

The Time To Live (TTL) of an item is the amount of seconds between when that item is stored and it is considered stale., (*7)

Warning: [apc.use_request_time][] needs to be set to false if you want to use that feature with APCU., (*8)

<?php

use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
$storage->store('icanboogie', "Yes Sir, I Can Boogie", $ttl = 3);
$storage->retrieve('icanboogie');   // "Yes Sir, I Can Boogie"
sleep(4);
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null

Use storage like arrays

Storage implements the ArrayAccess interface and may be accessed as arrays., (*9)

<?php

use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
isset($storage['icanboogie']);     // false
$storage['icanboogie'];            // null
$storage['icanboogie'] = "Yes Sir, I Can Boogie";
$storage['icanboogie'];            // "Yes Sir, I Can Boogie"
unset($storage['icanboogie']);
isset($storage['icanboogie']);     // false
$storage['icanboogie'];            // null

Iterate storage keys

Storage implements the IteratorAggregate interface and may be used in a foreach to iterate their keys:, (*10)

<?php

$storage['one'] = 1;
$storage['two'] = 2;
$storage['three'] = 3;

foreach ($storage as $key)
{
    echo "defined: $key\n";
}
defined: one
defined: two
defined: three

Adapter

The FileStorage storage uses adapters to write and read data written to the filesystem. Any class implementing the Adapter interface can be used, the following are provided with the package:, (*11)

  • SerializeAdapter: Uses serialize() and unserialize() to encode and decode data. It is used by default., (*12)

  • JSONAdapter: Uses json_encode() and json_decode() to encode and decode data., (*13)

  • PHPAdapter: Uses var_export() and require to encode and read data., (*14)

Storage collection

When implementing caches, it's always a good idea to use a collection of Storage instances that range from the less expensive (and the more volatile) to the more expensive (and the more durable)., (*15)

The following example demonstrates how a storage collection can be created with multiple storage instances:, (*16)

<?php

use ICanBoogie\Storage\StorageCollection;
use ICanBoogie\Storage\RunTimeStorage;
use ICanBoogie\Storage\APCStorage;
use ICanBoogie\Storage\RedisStorage;
use ICanBoogie\Storage\FileStorage;

$storage = new StorageCollection([

    new RunTimeStorage,
    new APCStorage('my-prefix'),
    new RedisStorage($redis_client, 'my-prefix'),
    new FileStorage('/path/to/directory')

]);

All the storage instances in the collection are updated by the store(), eliminate(), and clear() methods. Storage instances are also updated when values are retrieved from more expensive storages, so that the next time the value is requested it is retrieved from a less expensive storage., (*17)

Cache and Cache collection

The Cache interface and CacheCollection class implement a subset of the Storage interface and StorageCollection class, they only provide read-only features., (*18)

Support functions

  • APCStorage::is_available() may be used to check if APC is available.

Requirements

The package requires PHP 7.1 or later., (*19)

Installation

The recommended way to install this package is through Composer:, (*20)

$ composer require icanboogie/storage

Documentation

The package is documented as part of the ICanBoogie framework documentation. The documentation is generated by ApiGen, using the make doc command, in the build/docs directory. The directory can later be cleaned with the make clean command., (*21)

Local development & Testing

For local development, use the provided test container. You'll need Docker for that. Run make test-container to open a terminal session inside the container, then run make test to run the test suite. Alternatively, run make test-coverage to run the test suite and produce coverage report in build/coverag., (*22)

Travis CI continuously test the package., (*23)

Build Status Code Coverage, (*24)

License

icanboogie/storage is licensed under the New BSD License - See the LICENSE file for details., (*25)

The Versions

17/03 2018

dev-master

9999999-dev https://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

17/03 2018

v3.0.0

3.0.0.0 https://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

31/05 2017

3.0.x-dev

3.0.9999999.9999999-dev https://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

25/05 2017

dev-adapters

dev-adapters https://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

24/05 2017

dev-makefile

dev-makefile https://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

30/11 2016

v2.1.1

2.1.1.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

29/11 2016

v2.1.0

2.1.0.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

28/10 2015

v2.0.1

2.0.1.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

22/10 2015

v2.0.0

2.0.0.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

24/08 2015

v1.1.1

1.1.1.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

19/03 2015

v1.1.0

1.1.0.0 http://icanboogie.org/

Store and retrieve values, using different/multiple storage backends.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.0

 

cache store retrieve

27/02 2015

v1.0.1

1.0.1.0 http://icanboogie.org/

An API to store values.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

cache storage

13/01 2015

v1.0.0

1.0.0.0 http://icanboogie.org/

An API to store values.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

cache storage