NAME

Storage::Abstract::Driver::Composite - Aggregate metadriver

SYNOPSIS

my $storage = Storage::Abstract->new(
	driver => 'composite',
	source => [
		{
			driver => 'directory',
			directory => '/some/dir',
			readonly => !!1,
		}
		{
			driver => 'memory'
		},
	],
);

DESCRIPTION

This metadriver can hold a number of drivers under itself (in sequence) and choose the first driver which holds a given file.

Choosing the source

This driver will use the following logic to find a source suitable to store / retrieve a file:

  • Check the "source" array in order, starting from index 0.

  • If the source is readonly, skip it if the operation being performed is modifying the storage.

  • If the source doesn't report having this file (as with is_stored), skip it (unless we are storing).

  • If the source was not skipped in the previous steps, use it.

After the first successful pairing of a path with a source, it will be cached. Future operations on this path will prefer to use the cached source, but if they were to fail, they will fall back to checking all sources once again.

If any source raises an exception, the execution will stop since it will not be caught. Driver will check if the sources have the files stored explicitly, so NotFound exception should not be raised unless no sources store that file.

Unless you want to possibly have duplicated files in your sources, you should mark all but one nested drivers as readonly.

CUSTOM INTERFACE

Attributes

source

Required - An array reference of Storage::Abstract instances. Each instance can be coerced from a hash reference, which will be used to call "new" in Storage::Abstract. Their order is significant - they will be tried in sequence.

Methods

clear_cache

This method will clear the internal cache of the driver.

CAVEATS

This driver does not allow using set_readonly on it - trying to do so will always result in an exception (unblessed).