'"Global" cache in Spryker

I need to make HTTP requests directly from Yves controller. It is desirable to cache the result of this request in order to reduce the time of the entire operation. Do we have something like a quickly accessible system level (or "global") cache to inject into the Yves controller?



Solution 1:[1]

For quick dirty fix I would suggest using redis as key value storage.

DI for storage client

<?php

const CLIENT_STORAGE = 'CLIENT_STORAGE';

/**
 * @param \Spryker\Client\Kernel\Container $container
 *
 * @return \Spryker\Client\Kernel\Container
 */
public function provideServiceLayerDependencies(Container $container)
{
    $container[static::CLIENT_STORAGE] = function (Container $container) {
        return $container->getLocator()->storage()->client();
    };

    return $container;
}

Factory

<?php

 /**
 * @return \Spryker\Client\Storage\StorageClientInterface
 */
public function getStorageClient()
{
    return $this->getProvidedDependency(MyBundleDependencyProvider::CLIENT_STORAGE);
}

Accessing key

<?php
$storedValue = $this->storageClient->get($myKey);
if (!empty($storedValue)) {
    return $storedValue;
} 
// generate and return value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 walkingRed