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 Adapter Expiry Error #83

Open
Artemy-Matvienko opened this issue Mar 21, 2019 · 2 comments
Open

Cache Adapter Expiry Error #83

Artemy-Matvienko opened this issue Mar 21, 2019 · 2 comments
Assignees
Labels

Comments

@Artemy-Matvienko
Copy link

Artemy-Matvienko commented Mar 21, 2019

I've used the following 2 issues as references for what I have to do to implement caching with this library. #39 #19

The following is my adapter class for Simple Caching.

namespace App\classes;
use AlexaCRM\CRMToolkit\CacheInterface;
use Symfony\Component\Cache\Simple\FilesystemCache;

class CRMToolkitCacheAdapter implements CacheInterface {
    private $cache;
    
    public function __construct() {
        $this->cache = new FilesystemCache();
    }
    
    public function get( $key, $default = null ){
        return $this->cache->get($key, $default);
    }
    
    public function set( $key, $value, $expiresAfter = null ){
        $this->cache->set($key, $value, $expiresAfter);
    }
    
    public function delete( $key ){
        $this->cache->delete($key);
    }
    
    public function exists( $key ){
        return $this->cache->has($key);
    }
    
    public function cleanup(){
        $this->cache->clear();
    }
}

I've integrated the adapter into my code like so:

$serviceSettings = new Settings( $this->crm_config );
$cacheRepo = new CRMToolkitCacheAdapter();
$this->crm = new Client( $serviceSettings, $cacheRepo );

When I execute my app, I get the following error:

Type: Symfony\Component\Cache\Exception\InvalidArgumentException
Message: Expiration date must be an integer, a DateInterval or null, "double" given
File: /var/www/html/Sources/vendor/symfony/cache/Simple/AbstractCache.php
Line: 163

#0 /var/www/html/Sources/vendor/symfony/cache/Simple/AbstractCache.php(117): Symfony\Component\Cache\Simple\AbstractCache->normalizeTtl(32340)
#1 /var/www/html/Sources/vendor/symfony/cache/Simple/AbstractCache.php(72): Symfony\Component\Cache\Simple\AbstractCache->setMultiple(Array, 32340)
#2 /var/www/html/Sources/src/classes/CRMToolkitCacheAdapter.php(24): Symfony\Component\Cache\Simple\AbstractCache->set('discovery_secur...', Object(AlexaCRM\CRMToolkit\SecurityToken), 32340)
#3 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Auth/Authentication.php(104): App\classes\CRMToolkitCacheAdapter->set('discovery_secur...', Object(AlexaCRM\CRMToolkit\SecurityToken), 32340)
#4 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Auth/Federation.php(82): AlexaCRM\CRMToolkit\Auth\Authentication->getToken('discovery')
#5 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(1218): AlexaCRM\CRMToolkit\Auth\Federation->generateTokenHeader('discovery')
#6 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(1182): AlexaCRM\CRMToolkit\Client->generateSoapHeader('discovery', 'Execute')
#7 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(868): AlexaCRM\CRMToolkit\Client->generateSoapRequest('discovery', 'Execute', Object(DOMElement))
#8 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(2011): AlexaCRM\CRMToolkit\Client->AlexaCRM\CRMToolkit\{closure}()
#9 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(869): AlexaCRM\CRMToolkit\Client->attemptSoapResponse('discovery', Object(Closure))
#10 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(917): AlexaCRM\CRMToolkit\Client->retrieveOrganizations()
#11 /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php(166): AlexaCRM\CRMToolkit\Client->retrieveOrganization('https://org...')
#12 /var/www/html/Sources/src/classes/DataSource.php(117): AlexaCRM\CRMToolkit\Client->__construct(Object(AlexaCRM\CRMToolkit\Settings), Object(App\classes\CRMToolkitCacheAdapter))

Any idea what's causing this? "32340" doesn't seem like a double.

@Artemy-Matvienko
Copy link
Author

Artemy-Matvienko commented Mar 22, 2019

Just had to overwrite the value type in my adapter before passing it over, even though the CacheInterface specifically says that $expiresAfter should accept an integer, yet Authentication passes a double.

public function set( $key, $value, $expiresAfter = null ){
    $expiresAfter = intval($expiresAfter);
    $this->cache->set($key, $value, $expiresAfter);
}

@georged
Copy link
Contributor

georged commented Mar 22, 2019

Hi @Artemy-Matvienko

thanks for the workaround! I'll keep the issue open until we figure out what's the right solution is.

Cheers
George

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

No branches or pull requests

3 participants