Oracle 11g introduces a number of
features to expand the use of memory caching in order to
improve query performance. These features also
decrease the overall memory requirements of queries and
applications.
In addition to the features that support
server-side caching, which is discussed in Chapter 6,
there is also a new feature to support
a client-side result cache that allows OCI clients to fetch
result sets stored in process memory instead of requiring
access to the server's memory. The Client Result Cache
is enabled and configured at the database level and
available to all OCI-based clients.
Also see how to
activate Oracle Client Caching for OCI Applications.
Using the client's memory to cache query
result sets significantly improves the performance of
repetitive queries by OCI-based clients that would otherwise
require a cache hit on the server-side. The client
cache utilizes per-process memory on the OCI client and its
contents can be shared across multiple sessions and threads.
When executing repetitive queries, the clients fetch results
directly from the client cache rather than having the server
execute the query. In certain situations, this will
greatly reduce the number of round-trips between the client
and the database server. This also reduces CPU
consumption on the server and greatly increases the query
response times. Situations that will benefit most from
the client cache are queries that use small lookup tables or
mostly read-only tables.
The consistency between the client cache
and the database server is managed internally by the
database, and is a feature available to all OCI clients.
Configuring the Client Cache from the
Database
The current client cache initialization
parameters can be viewed by using:
SQL> show parameter client_result
NAME
TYPE VALUE
------------------------------------ ----------- -----
client_result_cache_lag
big integer 3000
client_result_cache_size
big integer 0
SQL>
To enable the client cache, the
initialization parameter
client_result_cache_size must be set to a value
greater than zero since the value of zero disables the
client cache. This parameter is the maximum size of
the client-per-process result set cache. All OCI
client processes get this maximum size.
The
client_result_cache_lag parameter specifies the
maximum amount of time, in milliseconds, that the client
result cache can lag behind any changes in the database that
affect the result sets. By default, the value is
3000ms (or three seconds). Since ideally this feature
is used for read-only tables, this setting should not have a
significant impact on the consistency of the cached results.
Both of these initialization parameters
are static parameters. This being, changing their values
should be done with SCOPE=SPFILE and any new values will not
become effective until the database is restarted. For
example, to enable the client cache with a value of 2M for
the client cache, issue the following:
SQL> alter system set client_result_cache_size=2M scope=SPFILE;
System altered.
After restarting the database, the new
settings have taken effect:
SQL> show parameter
client_result
NAME
TYPE VALUE
------------------------------------ ----------- -----
client_result_cache_lag
big integer 3000
client_result_cache_size
big integer 2M
SQL>