Configure Couchbase Memory Persistent Cache - SuperWEB2
To use the Couchbase Memory Persistent Cache strategy with SuperWEB2 you need to complete the following steps:
Step 1 - Download and Install Couchbase
- Download Couchbase Community Edition 1.8.0 from http://www.couchbase.com/download
-
Run couchbase-server-community_x86_64_1.8.0.setup.exe, following the instructions in the installation wizard.
-
When you are asked for the port number, enter 8091
-
When the installer completes, a web browser window will open and load http://localhost:8091/index.html
-
Follow the instructions in the wizard to configure Couchbase.
-
When you are asked whether to Start a new cluster or Join a cluster now, choose Start a new Cluster.
-
Leave the recommended Per Server Ram Quota as it is. This is the maximum amount of memory Couchbase can use for all data buckets.
Couchbase provides monitoring tools which will help you track the memory usage.
-
When you are asked for the type of server, choose MemCached.
-
You will then need to create a default bucket. Start with a bucket smaller than the Per Server RAM Quota. For example if the Per Server RAM Quota is 4663 MB, try 1024 MB.
You will be able to create more buckets up to the maximum size of the Per Server RAM Quota. - When the Notifications screen displays, click Next.
- When the Configure Server screen displays, enter a username and password for the new Administrator account and click Next.
- Then a Couchbase dashboard will be displayed with monitoring tools.
- Click Data Buckets in the left side menu, then click Create New Data Bucket on top right.
A new window displays.
- In the Bucket Name field, enter superweb2cache
- In the Bucket Type, select Couchbase
- In Access Control, select Standard port and enter a password (you will need this password when you configure web.xml in the next step).
- In Per Node RAM Quota, enter 512 MB for the memory size or any other size suitable for your caching needs for SuperWEB2. You can adjust the memory size later during runtime without loss of data and server restart.
- If there is only one server node, clear the Enable Replication check box.
- Click Create.
Step 2 - Configure web.xml
Once you have installed and configured Couchbase, you need to configure the following parameters in the web.xml configuration file. This file is located in <tomcat_home>\webapps\webapi\WEB-INF\
Parameter | Configures | Set To |
---|---|---|
memCachedServerExpiration | The cache expiration time in seconds. The default value is 0 which means no expiration. | 0 |
memCachedServerURL | The full URL to the Couchbase memcache server. | The URL, e.g. http://localhost:8091/pools |
couchbaseBucketName | The bucket name configured in Couchbase server to use as the SuperWEB2 cache. | The bucket name you selected during configuration. |
couchbaseBucketPassword | The password used to access the Couchbase bucket. | The password you selected during configuration. |
lruMapSize |
The size of the in-memory Least Recently Used map for storing table query results. You may wish to change this setting because the CouchBaseMemoryPersistentCache strategy uses LRUMap caching in addition to the cache stored in Couchbase. By default, it stores a maximum of 30 table query results. Please be aware that the bigger this number, the more memory you should allocate to Tomcat using the JVM options -Xmx. | The number of table queries to store in memory. The default value is 30. |
systemTableCacheStrategy |
The cache strategy for system defined tables stored in webapi\WEB-INF\resources\txd. |
CouchBaseMemoryPersistentCache |
otherTableCacheStrategy | The cache strategy for non-system defined tables. |
One of the following:
|
- Open web.xml in a text editor.
Make a backup copy of this file before making any changes.
-
Search for the Query Caching section:
CODE<!-- Query Caching Configuration --> <!-- 0 means never expire --> <context-param> <description>MemCached Server Cache Expiration Period</description> <param-name>memCachedServerExpiration</param-name> <param-value>0</param-value> </context-param> <context-param> <description>MemCached Server URL</description> <param-name>memCachedServerURL</param-name> <param-value>http://localhost:8091/pools</param-value> </context-param> <!-- "default" is the default bucketname when using with memcached bucket type --> <context-param> <description>Couchbase Server bucket name</description> <param-name>couchbaseBucketName</param-name> <param-value>superweb2cache</param-value> </context-param> <!-- Empty if no specified during Couchbase server configuration --> <context-param> <description>Couchbase Server bucket password</description> <param-name>couchbaseBucketPassword</param-name> <param-value>superweb2cache</param-value> </context-param> <context-param> <description>In-memory cache LRUMap size</description> <param-name>lruMapSize</param-name> <param-value>30</param-value> </context-param> <!-- Available cache strategy options: CouchBaseMemoryPersistentCache - Couchbase MemCached persistent cache would be used. Required params: memCachedServerExpiration, memCachedServerURL, lruMapSize LRUMemoryCache - In-memory LRU cache would be used. Required params: lruMapSize NoCache - No caching would be used. --> <context-param> <description>System Table Cache Strategy</description> <param-name>systemTableCacheStrategy</param-name> <param-value>NoCache</param-value> </context-param> <context-param> <description>Cache Strategy for rest of tables</description> <param-name>otherTableCacheStrategy</param-name> <param-value>NoCache</param-value> </context-param>
-
Set memCachedServerURL to the full URL of the Couchbase server. If you selected the default options, the URL should be http://localhost:8091/pools
- Leave memCachedServerExpiration set to 0.
- Set couchbaseBucketName to the Bucket Name you specified when you configured Couchbase.
- Set couchbaseBucketPasswordto the password you set when you configured Couchbase.
- Set lruMapSize to the number of table query results you want to cache in memory.
- Set systemTableCacheStrategy to CouchBaseMemoryPersistentCache.
- Set otherTableCacheStrategy to CouchBaseMemoryPersistentCache if you want to use CouchBaseMemoryPersistentCache for all kinds of table query including saved tables and ad-hoc created tables.
We recommend using LRUMemoryCache or NoCache for non-system tables as they are not commonly used tables and will require more memory which might jeopardise the performance of SuperWEB2 if insufficient memory is given to the machine.