Re: Getting object from cache?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Mar 07 2006 - 02:05:19 EST

  • Next message: Oscar Maire-Richard: "Re: Session persistence and initialization"

    Joe,

    this part did not change much, except for some cache refreshing
    tricks described here:

    http://objectstyle.org/confluence/display/CAYDOC/Caching+Query+Results

    Still individual objects and query results are disassociated from
    each other. I tried to explain why this is done in such way in this
    message:

    http://www.objectstyle.org/cayenne/lists/cayenne-devel/2006/02/0065.html

    So in your case you won't see a new object in the query caches until
    commit.

    Andrus

    On Mar 6, 2006, at 11:53 PM, McDaniel, Joe R. wrote:
    > I have not used Cayenne for about a year and thought I understood
    > how it works. I want to get a value from the database if it
    > exists, otherwise add it. If I add an object, I assumed it would be
    > retrieved from the cache on the next iteration needing that same
    > value, but that only happens if I have done a commit. Must I always
    > do a commit or is there some other magic to get what I want working
    > to do the "right thing?"
    >
    > Best,
    >
    > Joe
    >
    > Expression qual = ExpressionFactory.matchExp("lexical", value);
    >
    > SelectQuery query = new SelectQuery(Symbols.class, qual);
    >
    > // configure query to use local cache (supposedly this was the
    > "magic")
    > query.setName("FindSymbol");
    > query.setCachePolicy(GenericSelectQuery.LOCAL_CACHE);
    >
    > List values = ctxt.performQuery(query);
    >
    > Symbols symbol = null;
    > Long retval = null;
    > if(values == null || values.size() == 0)
    > {
    > // value does not exist, add new value
    > Symbols newSymbol = (Symbols)ctxt.createAndRegisterNewObject
    > (Symbols.class);
    > newSymbol.setLexical(value);
    > retval = new Long(pk++);
    > newSymbol.setHash(retval);
    > newSymbol.setDatatype(new Integer(0));
    > newSymbol.setLanguage(new Integer(0));
    > } else
    > {
    > symbol = (Symbols)values.get(0);
    > retval = symbol.getHash();
    > hits++
    > }
    > return retval;
    >



    This archive was generated by hypermail 2.0.0 : Tue Mar 07 2006 - 02:05:21 EST