Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Difference between cache-usage and maintain-cache query hints?

Hi Laird,

  Hopefully I can help.

Cache_Usage controls whether the cache is used to get results in a read. e.g. if you set the cache usage to CheckCacheThenDatabase when this query is executed, results in the cache will be prioritized over results in the DB.

Maintain_Cache is used to control whether returned results are put in the cache. If you set this to FALSE, no result returned by the query will be put in the cache.

The query cache can be enabled so that an individual query that is likely to always return the same results only goes to the database the first time for each set of parameters. e.g. In your query "SELECT s FROM State s ORDER BY s.code", since there are no query parameters, the first time you executed the query, the results would be cached and all future iterations would simply return those results.

  I'll file a bug for the confusing language in the query case doc.

-Tom


Laird Nelson wrote:
On Wed, Mar 16, 2011 at 4:10 PM, Laird Nelson <ljnelson@xxxxxxxxx <mailto:ljnelson@xxxxxxxxx>> wrote:

    My use case is the exceptionally brain-dead common example of
    caching a list of drop-down options.  The JPQL query in question is
    basically like one you'd write for U. S. states:

      SELECT s FROM State s ORDER BY s.code;

    If I wanted this query to return results from the cache whenever
    possible, which of these two query hints should I use?  Or is there
    (preferably) a JPA-sanctioned query hint that would do the same thing?


Wow, it's even more complicated: http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/config/QueryHints.html#QUERY_RESULTS_CACHE says, bafflingly:

    Configures the query to use a results cache. By default the query
    will cache 100 query results, such that the same named query with
    the same arguments is re-executed it will skip the database and just
    return the cached results.


That part isn't baffling--that sounds like exactly what I want! But then it goes on to say:

    Valid values are: HintValues.PERSISTENCE_UNIT_DEFAULT,
    HintValues.TRUE, HintValues.FALSE, "" could be used instead of
    default value HintValues.PERSISTENCE_UNIT_DEFAULT. By default query
    results are not cached. This is not, and is independent from the
    object cache.


(This is not...what?) What /is/ the default? Is it FALSE, or PERSISTENCE_UNIT_DEFAULT? If this is the way to handle this use case, why is it not mentioned here: http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_EclipseLink_JPA_Query_Hints? Does this mean that I cannot use eclipselink.query-results-cache as a JPA query hint? If I can, then why isn't it in the list of valid JPA query hints?

Benevolently confused,
Laird


------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top