Problem with cache (GAE)

Asked by ABBAnatic

I'm with GAE trying to cache a list of entities like this:

List<Post> list;
list = Cache.get("last7DaysList", List.class);
if(list == null) {
     JPAQuery lQ = Post.findBetweenDates(d0, d1, true);
     list = lQ.all(); // TODO cache this
        Cache.set("last7DaysList", list, "60mn");
}

Where Post extends JPASupport.

I'm getting this error on the line "Cache.set("last7DaysList", list, "60mn");" :
Cache error
Cannot cache a non-serializable value of type org.datanucleus.store.appengine.query.StreamingQueryResult

What's the problem?
Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
play framework Edit question
Assignee:
No assignee Edit question
Solved by:
Guillaume Bort
Solved:
Last query:
Last reply:
Revision history for this message
Best Guillaume Bort (guillaume-bort) said :
#1

This is because Datanucleus return a StreamingQueryResult as
List<Post> implementation, and it is not serializable.
As in GAE we use memcached, you can only cache Serializable values.

Perhaps you can try :

Cache.set("last7DaysList", new ArrayLIst(list), "60mn");

It will force Datanucleus to read all results from the Datastore and
create a clone.

On Mon, Jul 6, 2009 at 7:26 AM,
ABBAnatic<email address hidden> wrote:
> New question #76194 on play framework:
> https://answers.launchpad.net/play/+question/76194
>
> I'm with GAE trying to cache a list of entities like this:
>
> List<Post> list;
> list = Cache.get("last7DaysList", List.class);
> if(list == null) {
>        JPAQuery lQ = Post.findBetweenDates(d0, d1, true);
>        list = lQ.all(); // TODO cache this
>        Cache.set("last7DaysList", list, "60mn");
> }
>
> Where Post extends JPASupport.
>
> I'm getting this error on the line "Cache.set("last7DaysList", list, "60mn");" :
> Cache error
> Cannot cache a non-serializable value of type org.datanucleus.store.appengine.query.StreamingQueryResult
>
> What's the problem?
> Thanks!
>
> --
> You received this question notification because you are a member of play
> framework developers, which is an answer contact for play framework.
>

Revision history for this message
ABBAnatic (damian-pop) said :
#2

Thanks Guillaume Bort, that solved my question.