DBMS_CACHE Package
The DBMS_CACHE package facilitates the automatic caching for external table caches in an Autonomous AI Database instance.
Summary of DBMS_CACHE Subprograms
This table summarizes the subprograms included in the DBMS_CACHE package.
| Subprogram | Description |
|---|---|
| CLEAR Procedure | Clears all external table caches for a specified user. |
| GET_GLOBAL_PROPERTY Procedure | Retrieves external table caching properties. |
| GET_USER_PROPERTY Procedure | Retrieves external table caching properties for a specified user. |
| REFRESH Procedure | Refreshes all external table caches for a specified user. |
| SET_GLOBAL_PROPERTY Procedure | Specifies the external table caching preference for all database users. |
| SET_USER_PROPERTY Procedure | Specifies the external table caching preference for a specified user. |
CLEAR Procedure
Use the DBMS_CACHE.CLEAR procedure to drop all external table caches for a specified user.
The DBMS_CACHE.CLEAR procedure drops all the external table caches and release the storage space, similar to how the DROP command works on a database table.
Syntax
DBMS_CACHE.CLEAR (
owner IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
owner |
Specifies the schema name. |
Example
BEGIN
DBMS_CACHE.CLEAR (
owner => 'SALES');
END;
/
Usage Note
- You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to clear a cache.
GET_GLOBAL_PROPERTY Procedure
The DBMS_CACHE.GET_GLOBAL_PROPERTY procedure retrieves the external table caching preferences for all the users in the database. This procedure is overloaded.
Syntax
DBMS_CACHE.GET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_num OUT VARCHAR2);
DBMS_CACHE.GET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_str OUT VARCHAR2);
Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Retrieves a NUMBER value for the specified property name. |
property_value_str |
Retrieves a STRING value for the specified property name. |
Example
SET SERVEROUTPUT ON;
DECLARE
cache_property NUMBER;
BEGIN
DBMS_CACHE.GET_GLOBAL_PROPERTY (
property_name => 'MAX_CACHE_SIZE',
property_value => cache_property
);
DBMS_OUTPUT.PUT_LINE('MAX_CACHE_SIZE = ' || cache_property);
END;
/
Usage Note
- You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure.
SET_GLOBAL_PROPERTY Procedure
Use DBMS_CACHE.SET_GLOBAL_PROPERTY procedure to set AUTO caching properties for all database users, including those that enable automatic caching for the database. This procedure is overloaded.
By default, automatic caching of external tables is disabled. To enable it, set the cache size to a non-zero value using the MAX_CACHE_SIZE or MAX_CACHE_SIZE property of the DBMS_CACHE.SET_GLOBAL_PROPERTY procedure. This enables automatic caching globally for the database.
Syntax
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_num IN NUMBER);
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_str IN VARCHAR2);
Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Provides a NUMBER value for the specified property name. |
property_value_str |
Provides a STRING value for the specified property name. |
Examples
BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name => 'MAX_CACHE_SIZE',
property_value_num => 50);
END;
/
BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name => 'AUTO_REFRESH_MODE',
property_value_str => 'NEW');
END;
/
BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name => 'MAX_REFRESH_WINDOW',
property_value_num => 20);
END;
/
Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
The
MAX_REFRESH_WINDOWproperty specifies, in second, the maximum time allowed for refreshing external table caches. If the refresh exceeds the specified limit, the cache refresh exits normally, and any remaining eligible caches are queued for the next refresh cycle. -
When you refresh caches using the
DBMS_CACHE.REFRESHprocedure, the procedure parameter take precedence over theAUTO_REFRESH_MODEproperty.See REFRESH Procedure for more information.
REFRESH Procedure
Use the DBMS_CACHE.REFRESH procedure to refresh all the AUTO external table caches for a specified user.
Syntax
DBMS_CACHE.REFRESH (
owner IN VARCHAR2,
refresh_type IN VARCHAR2 DEFAULT ALL
);
Parameters
| Parameter | Description |
|---|---|
owner |
Specifies the schema name. |
refresh_type |
Specifies the refresh option. Following are the valid
This parameter is optional and defaults to |
Example
BEGIN
DBMS_CACHE.REFRESH (
owner => 'SALES',
refresh_type => 'CURRENT');
END;
/
Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
If you do not specify a value for the
refresh_typeparameter, Oracle perform refresh based onauto_refresh_modevalue. The default value forauto_refresh_modeisALL. -
When the
MAX_REFRESH_WINDOWproperty is set, Oracle attempts to perform refresh in the specified window. If the refresh exceeds the specified limit, the cache refresh exits normally, and any remaining eligible caches are queued for the next refresh cycle. -
All AUTO caches in the database are managed by using an eviction algorithm similar to Least Recently Used (LRU). When under space pressure, caches that have been accessed least recently are automatically dropped during the refresh process to release the storage space.
GET_USER_PROPERTY Procedure
Use the DBMS_CACHE.GET_USER_PROPERTY procedure to retrieve automatic caching properties for a user.
Syntax
DBMS_CACHE.GET_USER_PROPERTY (
property_name IN VARCHAR2,
owner IN VARCHAR2 DEFAULT NULL,
property_value_str OUT VARCHAR2);
DBMS_CACHE.GET_USER_PROPERTY (
property_name IN VARCHAR2,
owner IN VARCHAR2 DEFAULT NULL,
property_value_num OUT NUMBER);
Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
owner |
Specifies the schema name. This parameter is optional and defaults to the current schema. |
property_value_str |
Retrieves a STRING value for the specified property name. |
property_value_num |
Retrieves a NUMBER value for the specified property name. |
Example
SET SERVEROUTPUT ON;
DECLARE
cache_property NUMBER;
BEGIN
DBMS_CACHE.GET_USER_PROPERTY (
property_name => 'MAX_CACHE_SIZE',
owner => NULL,
property_value => cache_property
);
DBMS_OUTPUT.PUT_LINE('MAX_CACHE_SIZE = ' || cache_property);
END;
/
Usage Note
- You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure.
SET_USER_PROPERTY Procedure
Use the DBMS_CACHE.SET_USER_PROPERTY procedure to set AUTO caching properties for a specified schema, including those that enable automatic caching for the schema. This procedure is overloaded.
Syntax
DBMS_CACHE.SET_USER_PROPERTY (
property_name IN VARCHAR2,
property_value_num IN NUMBER,
owner IN VARCHAR2 DEFAULT NULL);
DBMS_CACHE.SET_USER_PROPERTY (
property_name IN VARCHAR2,
property_value_str IN NUMBER,
owner IN VARCHAR2 DEFAULT NULL
);
Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Provides a NUMBER value for the specified property name. |
property_value_str |
Provides a STRING value for the specified property name. |
owner |
Specifies the schema name. This parameter is optional and defaults to the current schema. |
Example
BEGIN
DBMS_CACHE.SET_USER_PROPERTY (
property_name => 'MAX_CACHE_SIZE',
property_value_num => 50,
owner => 'SALES');
END;
/
Usage Note
- You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure.