# Install DB Cache and Set Up Network

## Game database schema for DB cache

The database schema for DB cache can be configured as desired by the user.&#x20;

However, the following rules must be followed.

> * The RootUUID, OwnerUUID, and UUID fields must be present.
> * When RootUUID, OwnerUUUID, and UUID are specified as <mark style="color:orange;">Combination PK</mark>, it adversely affects search using indexing. Therefore, creating and using each index helps improve performance.
> * Among the above fields, the RootUUID and OwnerUUID are designated as <mark style="color:orange;">Non-Unique Index</mark>, and the UUID is designated as Primary Key.
> * The above field must be in varchar(38) format in MySQL and <mark style="color:orange;">uniqueidentifier</mark> format in MSSQL.
> * The names of the Root table and Child table must not be duplicated.
> * The <mark style="color:orange;">stored procedure</mark> used by the DB cache client and server are automatically added to the game database schema; do not modify or remove them.

<figure><img src="https://content.gitbook.com/content/Ceg6wWD81CFYby05yPX5/blobs/dQlTWI89TpZ0JQysvDh3/db_schema_ex.png" alt=""><figcaption><p>Example of a database schema for storing gamer data in an MMORPG</p></figcaption></figure>

**Example script for adding 3 required indexes**

```sql
ALTER TABLE dbo.Gamer ADD CONSTRAINT
 
PK_Gamer PRIMARY KEY CLUSTERED
 
(
 
UUID
 
) WITH( IGNORE_DUP_KEY = OFF) ON [PRIMARY]
 
 
 
CREATE INDEX IX_Gamer_OwnerUUID ON dbo.Gamer
 
(
 
OwnerUUID
 
) WITH( IGNORE_DUP_KEY = OFF) ON [PRIMARY]
 
 
 
CREATE INDEX IX_Gamer_RootUUID ON dbo.Gamer
 
(
 
RootUUID
 
) WITH( IGNORE_DUP_KEY = OFF) ON [PRIMARY]
```

## Prepare the DB cache server

After creating the database schema, you need to create a DB cache server instance. Only one instance of type <mark style="color:orange;">Proud.CDbCacheServer2</mark> is sufficient between each game server.

<table><thead><tr><th width="305">Instance</th><th>Description</th></tr></thead><tbody><tr><td>Proud.CDbCacheServer2.New</td><td>Creating an instance</td></tr><tr><td>Proud.CDbCacheServer2.Start</td><td>Execution</td></tr></tbody></table>

> * The connection string to connect to the DB instance is in the form of an ADO connection string, which you can see in the sample.
> * The authentication key of the DB cache server is the data sent by the DB cache client to identify the connection on the DB cache server.
> * When calling <mark style="color:orange;">Proud.CDbCacheServer2.Start</mark>, <mark style="color:orange;">Proud.CDbCacheServer2StartParameter.m\_tableNames</mark> must contain the table names defined by the user.
> * While <mark style="color:orange;">Proud.CDbCacheServer2.Start</mark> is running, <mark style="color:orange;">sp\_Get\<tablename>Data</mark>, <mark style="color:orange;">sp\_Remove\<tablename>Data</mark>, and <mark style="color:orange;">sp\_Add\<tablename>Data</mark> are automatically created.

## Prepare the DB cache client

Each game server (authentication server, game zone server, lobby server, etc.) must run <mark style="color:orange;">Proud.CDbCacheClient2.New</mark> to create a client instance of type <mark style="color:orange;">Proud.CDbCacheClient2</mark>.

After creation, you must attempt to connect to the DB cache server via <mark style="color:orange;">Proud.CDbCacheClient2.Connect</mark>. The connection attempt is asynchronous and <mark style="color:orange;">Proud.IDbCacheClientDelegate2.OnJoinDbCacheServerComplete</mark> is called when the connection succeeds or fails.\
The DB cache client internally uses <mark style="color:orange;">Proud.CLanClient</mark>, but since it is a thread pooling method, there is no separate FrameMove.<br>

To disconnect from the DB cache server, destroy the <mark style="color:orange;">Proud.CDbCacheClient2</mark> object or call <mark style="color:orange;">Proud.CDbCacheClient2.Disconnect</mark>. At this time, the DB cache client calls <mark style="color:orange;">Proud.IDbCacheClientDelegate2.OnLeaveDbCacheServer</mark>.

<br>
