Java client - Storing custom objects

Steven Grimm sgrimm at facebook.com
Fri Dec 8 09:38:39 UTC 2006


Does the class you're trying to store in the cache implement 
java.io.Serializable? If not, the memcached client won't be able to 
serialize it.

All about serialization:

http://java.sun.com/developer/technicalArticles/Programming/serialization/

-Steve


Jure Petrovic wrote:
> Hello, 
>
>
> how would you store a custom object in memcached using java client?
> Let's say we have a class like this:
>
> public class Adress {
> 	String street;
> 	int streetNum;
> 	int zipCode;
> 	String city;
> }
> 	
> I also implemented a getObject() method...
>
> public static Object getObject(String street, int streetNum, int
> zipCode, String city) {
> 		Adress ret = new Adress(street,streetNum,zipCode,city);
> 		return ret;
> 	}
>
>
> In my program now I do:
>
> Object a = Adress.getObject("Some street",10,1111,"Some City");
> .....
> Boolean bl = mc.set("adress", a);
>
>
> bl always evaluates to "false", and when I do mc.get() I always get an
> exception, saying that an object is null.
>
> Maybe someone knows how to store(serialize) object like that?
>
>
>
> I would really appreciate your help.
> Thank you in advance, 
>
> Jure Petrovic
>
>
>
>
>
>
>
>
>
>
>   



More information about the memcached mailing list