CREATE TABLE t (
i INT NOT NULL PRIMARY KEY
, c CLOB
, b BLOB
, nc NCLOB);
然后在TimeSten中定义CacheGroup:
CREATE DYNAMIC ASYNCHRONOUS WRITETHROUGH CACHE GROUP cg1
FROM t
(i INT NOT NULL PRIMARY KEY
, c VARCHAR2(4194304 BYTE)
, b VARBINARY(4194304)
, nc NVARCHAR2(2097152)
);
-----------------------------------------------------------------------------------------------------------------
3.先新建一个Cache Manager用户:
--------------------------------------------------------------------------------------------------------------------------------------
C:\Documents and Settings\zhangxsh.ETHER>ttisql
Copyright (c) 1996-2011, Oracle. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
Command> connect cache_session;
Connection successful: DSN=cache_session;UID=zhangxsh;
(Default setting AutoCommit=1)
Command> create user cacheadmin identified by cacheadm in;
User created.
Command> grant admin to cacheadm;
15151: GRANT failed: User CACHEADM does not exist
The command failed.
Command> grant admin to cacheadmin;
Command>
------------------------------------------------------------------
4.再新建一个Cache Table User
-------------------------------------------------------------------------------
Command> create user cache identified by cache;
User created.
Command> grant create session to cache;
Command>
---------------------------------------------------------------------------------
5.
Associate the Oracle Cache Administration user with the Cache Database(互相关联)
Command> connect "dsn=session_cache;uid=cacheadmin;oraclepwd=cacheadmin";
Enter password for 'cacheadmin':
Connection successful: DSN=session_cache;UID=cacheadmin;DataStore=C:\Times
(Default setting AutoCommit=1)
con1: Command> call ttcacheuidpwdset ('cacheadmin','cacheadmin');
con1: Command>
---------------------------------------------------------------------------------
6.Create a Cache Grid
con1: Command> call ttcacheuidpwdset ('cacheadmin','cacheadmin');
con1: Command> call ttcacheuidget;
< CACHEADMIN >
1 row found.
con1: Command> call ttgridcreate ('samplegrid');
con1: Command> call ttgridinfo;
< SAMPLEGRID, CACHEADMIN, NT, 32-bit, 11, 2, 2 >
1 row found.
con1: Command>
----------------------------------------------------------------------------------
7.
Associate the Cache Database with the Cache Grid
call ttgridnameset ('samplegrid');
======================================================================
将CacheGroup加入CacheDatabase
connect "dsn=cachedb1_1122;uid=cacheadm;pwd=cacheadm;oraclepwd=cacheadm";
call ttcachestart;
在Oracle中创建表:
-----------------------------------------------------------------------------------
-- Create table
create table T_SESSION
(
C_SID VARCHAR2(200) primary key ,
C_SESSION BLOB
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);
-- Grant/Revoke object privileges
grant select, insert, update, delete on T_SESSION to CACHEADMIN;
-----------------------------------------------------------------------------------
然后建立以下CacheGroup:
create [dynamic] asynchronous writethrough cache group g_awt from zhangxsh.t_session ( c_sid varchar(200) not null , c_session varbinary(262144),primary key(c_sid));
create
dynamic
asynchronous writethrough cache group g_awt from uss.t_session ( c_sid varchar(200) not null , c_session varbinary(262144),primary key(c_sid));
create
dynamic
asynchronous writethrough cache group g_awt from uss.t_session ( c_sid varchar(200) not null , c_session varbinary(262144),d_create timestamp,primary key(c_sid))
AGING USE timestamp LIFETIME 15 minutes CYCLE 5 seconds ON;
--------------------------------------------------------------------------------------
要启用自动回写:
call ttRepStart;--启用回写Agent
------------------------------------------
启用时间失效机制(Defining Cache Groups一节中有介绍):
每隔60秒检查when_placed截止现在超过45天的记录并删除。
CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP ordered_items
FROM oratt.orders
(ord_num NUMBER(10) NOT NULL,
cust_num NUMBER(6) NOT NULL,
when_placed DATE NOT NULL,
when_shipped DATE NOT NULL,
PRIMARY KEY(ord_num))
AGING USE when_placed LIFETIME 45 DAYS CYCLE 60 MINUTES ON,
oratt.order_item
(orditem_id NUMBER(12) NOT NULL,
ord_num NUMBER(10),
prod_num VARCHAR2(6),
quantity NUMBER(3),
PRIMARY KEY(orditem_id),
FOREIGN KEY(ord_num) REFERENCES oratt.orders(ord_num));