Simpler:

```php
$cacheOptions = $options->getCache();

if (is_string($cacheOptions)) {
    return $serviceLocator->get($cacheOptions);
}

if (is_array($cacheOptions)) {
    return StorageFactory::factory($cacheOptions);
}

return StorageFactory::factory(['adapter' => 'memory']);
```