Cache Hint

A query cache hint can be used to:

  • Indicate that a user query is eligible for result set caching and set the cache entry memory preference, time to live, etc.

  • Set the materialized view memory preference, time to live, or updatablity.

  • Indicate that a virtual procedure should be cachable and set the cache entry memory preference, time to live, etc.

/*+ cache[([pref_mem] [ttl:n] [updatable] [scope:session|user|vdb])]*/ sql ...
  • The cache hint should appear at the beginning of the SQL. It can be appear as any one of the leading comments. It will not have any affect on INSERT/UPDATE/DELETE statements or INSTEAD OF TRIGGERS.

  • pref_mem- if present indicates that the cached results should prefer to remain in memory. The results may still be paged out based upon memory pressure.

Care should be taken to not over use the pref_mem option. The memory preference is implemented with Java soft references. While soft references are effective at preventing out of memory conditions. Too much memory held by soft references can limit the effective working memory. Consult your JVM options for clearing soft references if you need to tune their behavior.
  • ttl:n- if present n indicates the time to live value in milliseconds. The default value for result set caching is the default expiration for the corresponding Infinispan cache. There is no default time to live for materialized views.

  • updatable- if present indicates that the cached results can be updated. This defaults to false for materialized views and to true for result set cache entries.

  • scope- There are three different cache scopes: session - cached only for current session, user - cached for any session by the current user, vdb - cached for any user connected to the same vdb. For cached queries the presence of the scope overrides the computed scope. Materialized views on the other hand default to the vdb scope. For materialized views explicitly setting the session or user scopes will result in a non-replicated session scoped materialized view.

The pref_mem, ttl, updatable, and scope values for a materialized view may also be set via extension properties on the view - using the teiid_rel namespace with MATVIEW_PREFER_MEMORY, MATVIEW_TTL, MATVIEW_UPDATABLE, and MATVIEW_SCOPE respectively. If both are present, the use of an extension property supersedes the usage of the cache hint.


The form of the query hint must be matched exactly for the hint to have affect. For a user query if the hint is not specified correctly, e.g. /*+ cach(pref_mem) */, it will not be used by the engine nor will there be an informational log. It is currently recommended that you verify (see Client Developers Guide) in your testing that the user command in the query plan has retained the proper hint.


Individual queries may override the use of cached results by specifying OPTION NOCACHE on the query. 0 or more fully qualified view or procedure names may be specified to exclude using their cached results. If no names are specified, cached results will not be used transitively.


No cached results will be used at all.

Specific NOCACHE
SELECT * from vg1, vg2, vg3 WHEREOPTION NOCACHE vg1, vg3

Only the vg1 and vg3 caches will be skipped, vg2 or any cached results nested under vg1 and vg3 will be used.

OPTION NOCACHE may be specified in procedure or view definitions. In that way, transformations can specify to always use real-time data obtained directly from sources.

results matching ""

    No results matching ""