Adding Libraries
The user needs to add all libraries located at %NC_HOME%/java/lib and %NC_HOME%/java/lib/resources
and %NC_HOME%/java/lib/integrations/nc-sessionprovider.jar
. If you are using IDE just add references to these files in the project, if you are not using IDE then you need to copy these files to 'WEB-INF/lib' folder under the application root folder.
- On Linux:
$NC_HOME/lib/
- On Windows:
%NC_HOME%/java/lib/
Defining Filter
After adding the required libraries in your application, you need to add the filter in the deployment descriptor of your web application. The deployment descriptor is a XML file named 'web.xml' located in the WEB-INF directory under the application root directory. The class file containing the filter implementation is:
com.alachisoft.ncache.web.sessionstate.NCacheSessionStoreProvider
To ensure the correct caching of sessions, you must apply this filter as the first filter in your deployment descriptor. Filters are executed in the order they are defined in deployment descriptor.
To configure a filter, you must define it first under the
NCache Session filter can be configured with the settings specified in 'session.xml' file located at %NC_HOME%/config. You must specify configPath with filter initialization parameter in order to load the configuration settings. The value of configPath must be the installation directory of NCache. The following is an example of how the deployment descriptor should look like after defining the filter. You can configure session module as single-regional or multi-regional module. For single-regional session state provider specify You have to specify one 'primary' and one or more 'secondary' caches for each web farm in For multi-regional session module, specify following configuration in session.xml file: Conceptual Overview<filter>
<filter-name>NCacheSessionProvider</filter-name>
<filter-class>com.alachisoft.ncache.web.session.NCacheSessionProvider</filter-class>
</filter>
<filter-mapping>
<filter-name>NCacheSessionProvider</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<init-param>
<param-name>configPath</param-name>
<param-value>%NC_HOME%/config</param-value>
</init-param>
Note
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<filter>
<filter-name>NCacheSessionProvider</filter-name>
<filter-class>com.alachisoft.ncache.web.session.NCacheSessionProvider</filter-class>
<init-param>
<param-name>configPath</param-name>
<param-value>%NC_HOME%/config</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>NCacheSessionProvider</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Single-Regional Session State Provider
session.xml
as:<?xml version="1.0" encoding="UTF-8"?>
<servlet-session-config>
<cache id="demoClusteredCache"/>
<log log-props="log4j.properties"/>
<locking enable-session-locking="true" retries-count="2" retry-interval="500ms" lock-timeout="36000ms" empty-session-when-locked="false"/>
</servlet-session-config>
Multi-Regional Session State Provider
session.xml
. The primary cache will be used for all local traffic and all secondary caches will be used when a user goes to different geography. The sid-prefix defined for each cache in the session.xml
file is added to the session ID. This sid-prefix helps in directing client to the cache holding the session.<servlet-session-config>
<log log-props="log4j.properties"/>
<locking enable-session-locking="true" retries-count="2" retry-interval="500ms" lock-timeout="36000ms" empty-session-when-locked="false"/>
<multi-site-cache secondary-connection-recycle-interval="0sec">
<primary-cache id="LondonCache" sid-prefix="LDNC"/>
<secondary-cache id="TokyoCache" sid-prefix="TKYC"/>
<secondary-cache id="NewYorkCache" sid-prefix="NYKC"/>
</multi-site-cache>
</servlet-session-config>
See Also
Deploying Application
Multi-site Java Session Support
Error Logging