Cache : incr() problem between implementation

114 views
Skip to first unread message

jsh

unread,
Jun 7, 2011, 10:40:55 AM6/7/11
to play-fr...@googlegroups.com
Hello,

I am facing a problem with the Play Cache. When using the incr(myKey) method, the cache content type must be different according to the cache implementation used.
When using the default ehCache implementation, the cache entry pointed by the key must be a numeric type (integer...) otherwise I get an exception:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
        at play.cache.EhCacheImpl.incr(EhCacheImpl.java:92)
        at play.cache.Cache.incr(Cache.java:146)
When using the memcached implementation the content must be a String..., otherwise I get that exception:
OperationException: CLIENT: CLIENT_ERROR cannot increment or decrement non-numeric value
        at net.spy.memcached.protocol.BaseOperationImpl.handleError(BaseOperationImpl.java:126)

Any idea on what I am supposed to do to be able to switch cache implementation at will?

Cheers.
Jérôme

jsh

unread,
Jun 7, 2011, 11:02:01 AM6/7/11
to play-fr...@googlegroups.com
Ok found this https://bugs.launchpad.net/play/+bug/503349 that seems to explain that the memcached client (spymemcached) is buggy.

Julien Tournay

unread,
Jun 7, 2011, 11:53:52 AM6/7/11
to play-fr...@googlegroups.com
Hi,

The problem with memcached is due to a (stupid ?) "optimization" made by the java client used by play.
Basically, all memcached client will encode Numbers to save space on the memcached server.

Problem is, since the stored values are "encoded", memcached is unable to incr or decr...
Last time I checked, this "feature" was not optional, in any of the clients.

jto.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/OFpXT1ZUandFQlVK.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



--
Real Programmers don't need comments-- the code is obvious.

Marc Deschamps

unread,
Jun 8, 2011, 3:21:15 AM6/8/11
to play-fr...@googlegroups.com
Give a try to Hazelcast module, incr and decr use AtomicNumber.

play install hazelcast-0.2.2


:-)

jsh

unread,
Jun 8, 2011, 7:01:22 AM6/8/11
to play-fr...@googlegroups.com
Yes, great, thanks.

But my concern was to have the same code working with all underlying implementation of the cache.
It seems we should not use incr() or decr() for that.
Reply all
Reply to author
Forward
0 new messages