Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache support #4

Closed
graphem opened this issue Aug 17, 2014 · 5 comments
Closed

Cache support #4

graphem opened this issue Aug 17, 2014 · 5 comments

Comments

@graphem
Copy link

graphem commented Aug 17, 2014

This is more a suggestion than a issue. I know that guzzle has a cache plugin. It will be great to see caching implemented in this sdk to speed up calls, as some of the call to isoft can be really time consuming and API has a rate limit. Thanks!

@mfairch
Copy link
Contributor

mfairch commented Aug 17, 2014

I like where you are going with this. Caching would be great however we have to be careful what we implement as we don't want the sdk to get very bloated.

@graphem
Copy link
Author

graphem commented Aug 17, 2014

Yeah maybe caching should be left to the discretion of the app built with the SDK. Good thing is that Guzzle Cache is embedded already so there is a way to extend it.

@andrewryno
Copy link
Contributor

For now, with the way the SDK is structured (this will probably improve soon) the best way would be to subclass the main Infusionsoft class, override getHttpClient with a new function, and do something like this (from the Guzzle Docs):

<?php

use Guzzle\Http\Client;
use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;
use Guzzle\Plugin\Cache\CachePlugin;
use Guzzle\Plugin\Cache\DefaultCacheStorage;

class SubInfusionsoft extends \Infusionsoft\Infusionsoft {

    /**
     * @return \Guzzle\Http\Client
     */
    public function getHttpClient()
    {
        $httpClient = new Client();

        $cachePlugin = new CachePlugin(array(
            'storage' => new DefaultCacheStorage(
                new DoctrineCacheAdapter(
                    new FilesystemCache('/path/to/cache/files')
                )
            )
        ));

        $httpClient->addSubscriber($cachePlugin);

        return $httpClient;
    }

}

Not ideal, but I'm looking to decouple the HTTP client a bit more to make it easier to do things like this in the future. Being able to customize the client is huge, especially for things like caching, inspecting requests via Runscope, or even other HTTP clients.

@andrewryno
Copy link
Contributor

Now that we have decoupled the HTTP client a little more, this should be easier. Probably even easier if we make the switch to Guzzle 4. But we could now work on getting this easier to implement by default.

@kressaty
Copy link
Contributor

As we're moving to using GH Issues more for actual issues, I'm going to close this out. If anyone wants to create a pull request please do so, but we've added this on the list of new features to consider in future versions of the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants