Open marcosinigaglia opened 11 years ago
You can only store things that are serializable and something you are trying to store is not. Some extra info that may be relevant: http://stackoverflow.com/questions/11600213/why-doesnt-java-lang-object-implement-the-serializable-interface
so lets say I have a case class. How do I make that serializable? When I try to cache an instance of my case class Product below I get an error.
case class Product(id: Int, title: Option[String], desc: Option[String], image: Option[String])
You can try java.io.Externalizable
to make your own class serializable.
Here's what I have tested:
Then I must implement some Java interface? I dont like that solution :)
Hi,
How about using MessagePack to serialize any object to bytes, then putting it in memcached?
I have read that Pinterest uses MessagePack and memcached this way :)
Unfortunately play.mvc.Results
is not serializable, then caching HTTP responses does not work:
@Cached(key = "homePage")
public static Result index() {
return ok("Hello world");
}
Stack:
java.io.NotSerializableException: play.mvc.Results$Status
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183) ~[na:1.7.0_60]
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) ~[na:1.7.0_60]
at com.github.mumoshu.play2.memcached.MemcachedPlugin$CustomSerializing.serialize(MemcachedPlugin.scala:96) ~[play2-memcached_2.10-0.6.0.jar:0.6.0]
at net.spy.memcached.transcoders.SerializingTranscoder.encode(SerializingTranscoder.java:162) ~[spymemcached-2.9.0.jar:2.9.0]
at net.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:291) ~[spymemcached-2.9.0.jar:2.9.0]
Any news on this one ?
This link helped me as a sample: https://gist.github.com/ramn/5566596 Inlining the important parts, @SerialVersionUID() and extends Serializable here since links can rot...
@SerialVersionUID(15L)
class Animal(name: String, age: Int) extends Serializable {
...
}
If you want to cache a Result
just use SerializableResult
:
https://github.com/playframework/playframework/blob/2.6.1/framework/src/play-cache/src/main/scala/play/api/cache/Cached.scala#L189
Hi, i try to use Memcache to store a ebean model object. I save the object but i have this exception: "java.io.NotSerializableException: play.libs.F$Tuple"
Any ideas? Thanks