mumoshu / play2-memcached

A memcached plugin for Play 2.x
Other
161 stars 66 forks source link

Empty keys - kind of ehcache compilance, avoiding IllegalArgumentExceptions #24

Closed mkubala closed 11 years ago

mkubala commented 11 years ago

Currently when you try to obtain/set/remove cached value for an empty key you will get following exception:

IllegalArgumentException: Key must contain at least one character. (StringUtils.java:73)
   net.spy.memcached.util.StringUtils.validateKey(StringUtils.java:73)
   net.spy.memcached.MemcachedConnection.enqueueOperation(MemcachedConnection.java:640)
   net.spy.memcached.MemcachedClient.asyncGet(MemcachedClient.java:847)
   com.github.mumoshu.play2.memcached.MemcachedPlugin$$anon$2.get(MemcachedPlugin.scala:104)
   (..)

I discover that some plugins (for example SecureSocial) which uses CacheAPI seems to be not tested with other implementation than default (Ehcache).

In my opinion it will be better to ignore empty keys and avoid exception. I'm aware that since CacheAPI does not establish any kind of 'cache keys contract' it is hard to determine who is responsible for guarding keys (client or concrete cache api implementation?) so do with this pull request what you want ;)

mumoshu commented 11 years ago

Hi, @mkubala

Thank you for the pull request! I have just merged it.

I totally agree with your opinion about ignoring empty keys and avoid exceptions.

I think that the default - Ehcache - implementation is, essentially, a reference implementation for all the CacheAPI implementations including play2-memcached, since I also believe many people seem to not test their applications/plugins with implementations other than the default, as you pointed out too!

Thanks

mumoshu