@@ -538,7 +538,7 @@ For installation information, see the [Node-oracledb Installation Instructions][
538
538
- 31.1 [Tuning Fetch Performance](#rowfetching)
539
539
- 31.2 [Database Round-trips](#roundtrips)
540
540
- 31.3 [Statement Caching](#stmtcache)
541
- - 31.4 [Client Result Cache ](#clientresultcache)
541
+ - 31.4 [Client Result Caching (CRC) ](#clientresultcache)
542
542
32. [Tracing SQL and PL/SQL Statements](#tracingsql)
543
543
33. [Node.js Programming Styles and node-oracledb](#programstyles)
544
544
- 33.1 [Callbacks and node-oracledb](#callbackoverview)
@@ -16957,35 +16957,56 @@ satisfaction.
16957
16957
[SODA](#sodaoverview) internally makes SQL calls, so tuning the statement cache
16958
16958
is also beneficial for SODA applications.
16959
16959
16960
- ### <a name="clientresultcache"></a> 31.4 Client Result Cache
16960
+ ### <a name="clientresultcache"></a> 31.4 Client Result Caching (CRC)
16961
16961
16962
- Node-oracledb applications can use Oracle Database's [Client Result Cache][180].
16963
- The CRC enables client-side caching of SQL query (SELECT statement) results in
16964
- client memory for immediate use when the same query is re-executed. This is
16965
- useful for reducing the cost of queries for small, mostly static, lookup tables ,
16966
- such as for postal codes. CRC reduces network [round-trips](#roundtrips), and
16967
- also reduces database server CPU usage.
16962
+ Node-oracledb applications can use Oracle Database's [Client Result Cache][180]
16963
+ ( CRC). This enables client-side caching of SQL query (SELECT statement)
16964
+ results in client memory for immediate use when the same query is re-executed.
16965
+ This is useful for reducing the cost of queries for small, mostly static,
16966
+ lookup tables, such as for postal codes. CRC reduces network
16967
+ [round-trips](#roundtrips) and also reduces database server CPU usage.
16968
16968
16969
16969
The cache is at the application process level. Access and invalidation is
16970
16970
managed by the Oracle Client libraries. This removes the need for extra
16971
- application logic, or external utilities, to implement a cache.
16971
+ application logic, or external utilities, to implement a cache. Pooled
16972
+ connections can use CRC. Repeated statement execution on a standalone
16973
+ connection will also use it, but sequences of calls using standalone
16974
+ connections like `oracledb.getConnection({user:
16975
+ ...})`/`execute()`/`connection.close()` will not. CRC requires [statement
16976
+ caching](#stmtcache) to be enabled, which is true by default.
16972
16977
16973
- CRC can be enabled by setting the [database parameters][181]
16974
- `CLIENT_RESULT_CACHE_SIZE` and `CLIENT_RESULT_CACHE_LAG`, and then restarting
16975
- the database, for example:
16978
+ ##### Configuring CRC
16979
+
16980
+ Client Result Caching can be enabled by setting the [database parameters][181]
16981
+ `CLIENT_RESULT_CACHE_SIZE` and `CLIENT_RESULT_CACHE_LAG`, for example:
16976
16982
16977
16983
```sql
16978
16984
SQL> ALTER SYSTEM SET CLIENT_RESULT_CACHE_LAG = 3000 SCOPE=SPFILE;
16979
16985
SQL> ALTER SYSTEM SET CLIENT_RESULT_CACHE_SIZE = 64K SCOPE=SPFILE;
16986
+ ```
16987
+
16988
+ Then restart the database:
16989
+
16990
+ ```
16980
16991
SQL> STARTUP FORCE
16981
16992
```
16982
16993
16983
- Once CRC has been enabled in the database, the values used by the cache in
16984
- Node.js can be tuned in an [`oraaccess.xml`](#oraaccess) file, see [Client
16985
- Configuration Parameters][182].
16994
+ or restart the [pluggable database](#startupshutdownpdb), for example:
16995
+
16996
+ ```
16997
+ SQL> ALTER PLUGGABLE DATABASE CLOSE;
16998
+ SQL> ALTER PLUGGABLE DATABASE OPEN;
16999
+ ```
17000
+
17001
+ Once CRC has been enabled in the database, the values used by the cache can
17002
+ optionally be tuned in an [`oraaccess.xml`](#oraaccess) file, see [Client
17003
+ Configuration Parameters][182]. Also see [Tuning the Result Cache][203], which
17004
+ discusses CRC and also the Server Result Cache.
17005
+
17006
+ ##### Using CRC
16986
17007
16987
- Tables can be created, or altered, so repeated queries use CRC. This allows
16988
- existing applications to use CRC without needing modification. For example:
17008
+ Tables can be created, or altered, so queries use CRC. This allows
17009
+ applications to use CRC without needing modification. For example:
16989
17010
16990
17011
```sql
16991
17012
SQL> CREATE TABLE cities (id NUMBER, name VARCHAR2(40)) RESULT_CACHE (MODE FORCE);
@@ -16998,39 +17019,51 @@ Alternatively, hints can be used in SQL statements. For example:
16998
17019
SELECT /*+ result_cache */ postal_code FROM locations
16999
17020
```
17000
17021
17022
+ ##### Verifying CRC
17023
+
17001
17024
To verify that CRC is working, you can check the number of executions of your
17002
- query from `V$SQLAREA` and compare it with an uncached query. When CRC is
17003
- enabled, the number of statement executions is reduced because the statement is
17004
- not sent to the database unnecessarily.
17025
+ query in `V$SQLAREA`. When CRC is enabled in the database, the number of
17026
+ statement executions is reduced because the statement is not sent to the
17027
+ database unnecessarily.
17005
17028
17006
17029
```javascript
17007
17030
// Run some load
17008
17031
const q = `SELECT postal_code FROM locations`;
17009
17032
const qc = `SELECT /*+ RESULT_CACHE */ postal_code FROM locations`;
17033
+
17010
17034
for (let i = 0; i < 100; i++) {
17035
+ connection = await oracledb.getConnection();
17011
17036
result = await connection.execute(q);
17037
+ await connection.close();
17038
+ }
17039
+
17040
+ for (let i = 0; i < 100; i++) {
17041
+ connection = await oracledb.getConnection();
17012
17042
result = await connection.execute(qc);
17043
+ await connection.close();
17013
17044
}
17014
17045
17015
- // Compare behaviors
17046
+ // Compare behaviors (using a connection as SYSTEM)
17016
17047
const m = `SELECT executions FROM v$sqlarea WHERE sql_text = :q1`;
17048
+
17017
17049
result = await systemconn.execute(m, [q]);
17018
- console.log('No CRC:', result.rows[0][0], 'executions');
17050
+ console.log('No hint:', result.rows[0][0], 'executions');
17051
+
17019
17052
result = await systemconn.execute(m, [qc]);
17020
- console.log('CRC:', result.rows[0][0], 'executions');
17053
+ console.log('CRC hint :', result.rows[0][0], 'executions');
17021
17054
```
17022
17055
17023
17056
When CRC is enabled, output will be like:
17024
17057
17025
17058
```
17026
- No CRC : 100 executions
17027
- CRC: 1 executions
17059
+ No hint : 100 executions
17060
+ CRC hint : 1 executions
17028
17061
```
17029
17062
17030
17063
If CRC is not enabled, output will be like:
17031
17064
```
17032
- No CRC : 100 executions
17033
- CRC: 100 executions
17065
+ No hint : 100 executions
17066
+ CRC hint : 100 executions
17034
17067
```
17035
17068
17036
17069
## <a name="bindtrace"></a> <a name="tracingsql"></a> 32. Tracing SQL and PL/SQL Statements
@@ -17618,3 +17651,4 @@ can be asked at [AskTom][158].
17618
17651
[200]: https://blogs.oracle.com/opal/demo:-graphql-with-node-oracledb
17619
17652
[201]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-19E0F73C-A959-41E4-A168-91E436DEE1F1
17620
17653
[202]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-C941CE9D-97E1-42F8-91ED-4949B2B710BF
17654
+ [203]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-39C521D4-5C6E-44B1-B7C7-DEADD7D9CAF0
0 commit comments