caching of query results

From: Bryan Lewis (brya..aine.rr.com)
Date: Wed Jan 26 2005 - 22:48:06 EST

  • Next message: Robert Zeigler: "Re: caching of query results"

    I have a moderately complicated query in my app's home page that fetches a list of news stories. I want to fetch the stories from the database only once every ten minutes. In our old WebObjects app that we're converting, we kept a simple static code-cache of the list of objects. That wouldn't be a good thing to do in Java because the static reference would prevent the list from being garbage collected. (Feel free to correct me anywhere in here; I've just spent my first day with a java memory profiler.) Besides, I've got Cayenne to do the caching work for me, right?

    I've tried a couple of ways to ask Cayenne to cache the results of a query, but I must be missing something.

    I tried a simple SelectQuery with setRefreshingObjects(false), expecting that would avoid the SQL query, but it doesn't.

    I tried a named query. It's too complicated to express in the modeler, so I do it in code like:

        if (firstTime) {
            // Create the query.
            query.setName(uniqueName);
            myDataMap.addQuery(query);
       }

    Then I call dataContext.performQuery(uniqueName, false) when I don't want to refresh. But again, this doesn't avoid the SQL statement.

    If this approach isn't going to work, what do other people do in this situation? I suppose I could statically cache DataRows which are a lot lighter-weight than DataObjects.

    Thanks,
    Bryan Lewis

     



    This archive was generated by hypermail 2.0.0 : Wed Jan 26 2005 - 22:48:26 EST