TimesTen 应用层数据库缓存学习:2. 缓存组分类

Cache Group,简单来说,就是在TimesTen中建立Oracle表的内存缓存,然后数据在两者之间自动同步。如下图,Oracle中黄颜色的表称为cached table,TimesTen中绿色的表称为cache table.
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第1张图片

TimesTen中Cache Group有很多类型,如下图,这张图对于了解Cache Group的概念非常重要:
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第2张图片

红框内的类型是最常用的,我们先只关注此部分。

主类型

左侧定义了cache group的主类型,Read-only和AWT是最常用的;
Read-only: 只读,数据在Oracle端更新,然后异步刷新到TimesTen
AWT: 读写,数据在TimesTen更新,然后异步复制到Oracle

数据加载的方式

上方定义了数据加载到Cache Group的方式,分为Explicitly load和Dynamic Load。Explicitly load为缺省。
Explicitly Load的定义为:

In an explicitly loaded cache group, cache instances are loaded manually into the TimesTen cache tables from an Oracle database by using a load or refresh operation or automatically by using an autorefresh operation. The cache tables are loaded before operations such as queries are performed on the tables. An explicitly loaded cache group is appropriate when the set of data to cache is static and can be predetermined before applications begin performing operations on the cache tables. By default, cache groups are explicitly loaded unless they are defined as dynamic.

Dynamic Load定义为:

You can perform a dynamic load for queries with equality conditions on all columns in primary keys, with equality conditions on all columns in unique indexes, or with a mixture of equality or IS NULL conditions on all columns in unique indexes (provided that at least one equality condition is used).

In a dynamic cache group, data is automatically loaded into the TimesTen cache tables from the cached Oracle Database tables when a qualifying SELECT, INSERT, UPDATE, or DELETE statement is issued on one of the cache tables and the data does not exist in the cache table but does exist in the cached Oracle Database table.

那么什么是qualifying呢?就是下面括号中粗体的部分

A dynamic load retrieves a single cache instance that is either automatically loaded from the Oracle database to the TimesTen database or, for dynamic global cache groups, transferred from the grid member that owns the instance to the requesting grid member. A cache instance consists of row from the root table of any cache group (that is uniquely identified by either a primary key or a unique index on the root table) and all related rows in the child tables associated by foreign key relationships.

Dynamic Load适合的场景为:

A dynamic cache group is appropriate when the set of data to cache is small and should not be preloaded from Oracle Database before applications begin performing operations on the cache tables.

数据共享方式

下方定义了在TimesTen数据库间是否共享数据,
Local:缺省,不共享,数据是私有的
Global: 共享,即cache grid。数据是全局的,每一个cache instance只有一个属主(TimesTen数据库)。只有AWT Cache Group支持Global方式

下面我们再来看下SQLDeveloper中Cache Group定义界面:
下图为Cache Group类型:
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第3张图片
Global 和Dynamic CheckBox缺省都没有选中,表示缺省的Cache Group为Local, Explicitly Load
选中Global,发现只有AWT支持
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第4张图片
选中Readonly,其下还可定义更细的属性,此处比较重要的是Refresh Interval,即数据同步频率,其它的属性会在后文中单独解释
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第5张图片

我们发现还有一个重要的属性,即

Aging

TimesTen中的普通表和Cache Table都支持Aging。
Aging分为基于时间和基于用量(LRU)两种。基于时间的Aging要求cached table有一列类型为TIMESTAMP or DATE。Life-time为生命周期,Cycle为检查的周期,又称为Aging Cycle。原理为:

The value of this column is subtracted from SYSDATE, truncated using the specified unit (minute, hour, day) and then compared to the LIFETIME value. If the result is greater than the LIFETIME value, then the row is a candidate for aging.

TimesTen 应用层数据库缓存学习:2. 缓存组分类_第6张图片
LRU可以用于:

基于用量的Aging考量的是整个数据库的内存用量,相对于PermSize总量。可以用ttAgingLRUConfig调整上下限和Aging Cycle。
TimesTen 应用层数据库缓存学习:2. 缓存组分类_第7张图片

LRU aging can be defined for all cache group types except explicitly loaded autorefresh cache groups. LRU aging is defined by default on dynamic cache groups.

参考:
* Oracle® TimesTen Application-Tier Database Cache User’s Guide | 1. TimesTen Application-Tier Database Cache Concepts | Loading data into a cache group: Explicitly loaded and dynamic cache groups
* Oracle® TimesTen Application-Tier Database Cache User’s Guide | 5. Cache Group Operations | Dynamically loading a cache instance

你可能感兴趣的:(分类,timesten,缓存组)