ScriptFUSION / Porter

:lipstick: Durable and asynchronous data imports for consuming data at scale and publishing testable SDKs.
GNU Lesser General Public License v3.0
611 stars 24 forks source link

Laravel and CachingConnector? #60

Closed 4n70w4 closed 4 years ago

4n70w4 commented 5 years ago

How to enable CachingConnector in Laravel?

    public function handle() {
        app()->bind(HttpConnector::class, CachingConnector::class);

        app()->bind(EuropeanCentralBankProvider::class, EuropeanCentralBankProvider::class);

        $porter = new Porter(app() );

        $specification = new ImportSpecification(new DailyForexRates() );
        $specification->enableCache();
        $rates = $porter->import($specification);

        foreach ($rates as $rate) {
            echo "$rate[currency]: $rate[rate]\n";
        }

    }

ScriptFUSION\Porter\Cache\CacheUnavailableException : Cannot cache: connector does not support caching.

Bilge commented 5 years ago

Sorry, I don't know anything about Laravel. The error means the connector that's being used to import DailyForexRates is not CachingConnector, but some other class. If you want to cache responses from the HttpConnector, you need to wrap the HttpConnector with the CachingConnector, so it would look like the following.

new CachingConnector(new HttpConnector);

I do not know how to do this with Laravel, but essentially you need to inject HttpConnector inside CachingConnector and then inject that CachingConnector into EuropeanCentralBankProvider. Unfortunately, it seems EuropeanCentralBankProvider only supports HttpConnector, though, so we would need to fix that!

Bilge commented 4 years ago

This is fixed in EuropeanCentralBankProvider version 5.