[Doctrine] Cache in use

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Doctrine] Cache in use

jmleroux
Hello,

I configured Doctrine ORM module to use Memcached.

Is there an easy way to verify that the cache is correctly used ?

With ZF dev tools for example ?

Thanks,

JM Leroux
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

Marco Pivetta
The fastest way to see if your cache is set, is checking your ORM
configuration:

$entityManager->getConfiguration() contains all the details that you want
to check.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 18 March 2014 12:09, LEROUX Jean-Marie <[hidden email]> wrote:

> Hello,
>
> I configured Doctrine ORM module to use Memcached.
>
> Is there an easy way to verify that the cache is correctly used ?
>
> With ZF dev tools for example ?
>
> Thanks,
>
> JM Leroux
>
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
My mistake : i did not see my queries cached in ZDT toolbar, because i did
not use a '$query->useResultCache(true)'.

Now i can see they are cached.

I'm testing the use of '$query->setHydrationCacheProfile(new
QueryCacheProfile(10));' which cache my results, but it seems the lifetime
is not taken into account by my Zend\Storage\Memcached.

More on this later.

Thanks for the help.

:)


2014-03-18 13:52 GMT+01:00 Marco Pivetta <[hidden email]>:

> The fastest way to see if your cache is set, is checking your ORM
> configuration:
>
> $entityManager->getConfiguration() contains all the details that you want
> to check.
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
> On 18 March 2014 12:09, LEROUX Jean-Marie <[hidden email]> wrote:
>
>> Hello,
>>
>> I configured Doctrine ORM module to use Memcached.
>>
>> Is there an easy way to verify that the cache is correctly used ?
>>
>> With ZF dev tools for example ?
>>
>> Thanks,
>>
>> JM Leroux
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

Marco Pivetta
On 18 March 2014 14:56, LEROUX Jean-Marie <[hidden email]> wrote:

> My mistake : i did not see my queries cached in ZDT toolbar, because i did
> not use a '$query->useResultCache(true)'.
>
> Now i can see they are cached.
>
> I'm testing the use of '$query->setHydrationCacheProfile(new
> QueryCacheProfile(10));' which cache my results, but it seems the lifetime
> is not taken into account by my Zend\Storage\Memcached.
>

This was actually tested/implemented in
https://github.com/doctrine/DoctrineModule/pull/345 - maybe a bug?

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
Maybe.
I am using a DoctrineModule\Cache\ZendStorageCache and i do not see any lifetime set :

https://github.com/doctrine/DoctrineModule/blob/master/src/DoctrineModule/Cache/ZendStorageCache.php#L76


ongoing analysis...
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
The fact is we cannot (easily) change the ttl of a Zend\Cache\Storage\Adapter\AbstractAdapter for a given item.

It seems that this is a good candidate for a PR.
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
It works as a proof of concept with these modifications

-----------------------------------------------------------------------------------------
Zend\Cache\Storage\Adapter\AbstractAdapter
-----------------------------------------------------------------------------------------
    abstract protected function internalSetItem(& $normalizedKey, & $value, $ttl = 0);

-----------------------------------------------------------------------------------------
Zend\Cache\Storage\StorageInterface
-----------------------------------------------------------------------------------------

    public function setItem($key, $value, $ttl = 0);

-----------------------------------------------------------------------------------------
Zend\Cache\Storage\Adapter\Memcached
-----------------------------------------------------------------------------------------
    protected function internalSetItem(& $normalizedKey, & $value, $ttl = 0)
    {
        $memc       = $this->getMemcachedResource();
        $expiration = $ttl ? $ttl : $this->expirationTime();
        if (!$memc->set($this->namespacePrefix . $normalizedKey, $value, $expiration)) {
            throw $this->getExceptionByResultCode($memc->getResultCode());
        }

        return true;
    }


and finally
-----------------------------------------------------------------------------------------
DoctrineModule\Cache\ZendStorageCache
-----------------------------------------------------------------------------------------
    protected function doSave($id, $data, $lifeTime = false)
    {
        return $this->storage->setItem($id, $data, $lifeTime);
    }


So i have to make a PR an ZF2 (on all storage adpaters for setItem signature) *AND* DoctrineModule.

And find the test for $ttl.


Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
In reply to this post by jmleroux
I made a PR here : https://github.com/zendframework/zf2/pull/6001

If this is accepted, I will make a PR for Zend cache adapter in Doctrine Module
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

Marco Pivetta
As discussed on #6001, ZF2 can't have per-item TTL by default. It is
trivial to implement a small wrapper for it, as I've written at
https://github.com/zendframework/zf2/pull/5386#issuecomment-29386320

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 19 March 2014 16:39, jmleroux <[hidden email]> wrote:

> I made a PR here : https://github.com/zendframework/zf2/pull/6001
>
> If this is accepted, I will make a PR for Zend cache adapter in Doctrine
> Module
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Doctrine-Cache-in-use-tp4661873p4661891.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [Doctrine] Cache in use

jmleroux
I made another try, in DoctrineModule this time. ;)